Lecture 2 Flashcards

1
Q

GDB run does what?

A

Executes the program

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

gdb break does what?

A

set a breakpoint (a place for the program to stop)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

gdb next

A

Run until the next instruction in this function(don’t follow function calls)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

gdb step

A

Stop at the next instruction call anywhere (goes into function calls)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

gdb continue

A

run until the next breakpoint

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

gdb print

A

show the value of a variable

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

gdb set

A

change the value of a variable

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

gdb jump

A

Start executing at a different line number

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

gdb enable/disable

A

enable or disable breakpoints

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is the standard format of a switch?

A
switch(class) {
1: report 1
2: report 2
3: report 3
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What are the five ways to leave a loop iteration in c?

A
  • Finish the code flow in the loop
  • Continue-command that says to go to the next loop iteration
  • Break-leave the current block of code
  • Goto: has you redirect to a specific line of the program, identified by a label
  • Return: leave the current function completely
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Why are we discouraged from using goto?

A

To avoid ‘spaghetti code’.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is a useful purpose of goto?

A

Is to jump to error code before leaving the function

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Why do some style guides prefer having a single exit point for a loop or function?

A

Makes for easier debugging and understanding of when you have left the block of code

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What do functions return?

A

A return statement

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Do procedures also return a return statement?

A

Nope!

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

How should you aim to keep functions?

A

Small and with a well defined purpose

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

Can variables declared inside of a function or procedure be used outside of the function?

A

Nope!

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

What happens to values of variables once the function is complete

A

They disappear

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

How can you prevent variable values from disappearing once the function is complete?

A

Use a static variable

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

What are the four parts of a running program?

A

Executable code of the program

Global variables

Call stack

Heap

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

Which sections of the anatomy of a running program are created at compile time?

A

The executable code and the global variables

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

What type of data structure is the call stack?

A

LIFO; last in first out

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

When we call a function, what is created?

A

A stack frame

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q

Where is the stack frame added once a function is called?

A

The call stack

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
26
Q

What does a stack frame contain?

A

The instructions to execute in the calling function when the function ends

Hardware information that the current function will change and need to be restored for the calling function

The parameters for the function

Space for local variables for the function

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
27
Q

What happens when the function ends?

A

The stack frame for the function is removed from the call stack, so all the information disappears.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
28
Q

What is always bottom of the stack?

A

Main local variables

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
29
Q

What data type of a single character?

A

A char data type

30
Q

Is a single character a byte?

A

Yes!

31
Q

Does char hold unicode values?

A

no, it is treated as a byte (number

32
Q

What is \n?

A

Carriage return

33
Q

What is \r?

A

Line feed

34
Q

What is \r used for?

A

Network protocols

35
Q

Wat is \t?

A

Tab character

36
Q

What is a C string?

A

C strings are arrays of characters

37
Q

How do you identify the end of a string?

A

With a NULL character?

38
Q

How do you assign, compare, copy or work on strings?

A

Using a string library to do the work

39
Q

What is argc?

A

Argument count: the number of strings in the list of parameters

40
Q

What is argv?

A

Argument values- the strings passed to the program

41
Q

How do we manage arguments?

A

Main is always provided with at least one argument: the name of the program when it was invokved

42
Q

How does the name of the program appear?

A

Always appears as argh[0]

43
Q

Typical steps for a main function?

A

Set up default values for parameters

Loop through all of arg v to store parameters updates get on with the typical work

44
Q

How do you include a C string library?

A

include

45
Q

What does strlen do?

A

Return the number of characters in the string

46
Q

Is strcmp safe or unsafe?

A

unsafe

47
Q

What is the printing pattern for a double?

A

%f

48
Q

What is the printing value for a char?

A

%c

49
Q

For signed data, what bit identifies whether the data is positive or negative?

A

The leftmost bit

50
Q

What does the const modifier do

A

Flag that this variables value shouldn’t change after initialization

Often used in parameter declarations

51
Q

What does the static modifier do?

A

For a local variable, ask for its space to be somewhere other than the stack so the value survives across function invocations

52
Q

Type coercions go in one direction? True or False

A

True

53
Q

What does the command typedef do?

A

Lets you give a different name to existing commands

54
Q

What are three ways to create your own data types?

A
  • Struct
  • Enum
  • Union
55
Q

Which two data type creation methods can nest within one another?

A

Structs and unions

56
Q

Where can an enum appear?

A

Inside a struct or a union

57
Q

What is the structure of a typedef?

A

typedef struct {
float x;
float y;
} point;

point p;

p. x = 5
p. y = 10.5

58
Q

How do you initialize a stack?

A
  • Set the stack to have no entries
  • Store the size of the stack
  • Return whether or not the initialization is successful
59
Q

How do you destroy a stack?

A

Reset the stack to be empty

Nothing to return..what can the user do if we don’t clean up properly? nothing, so no use telling them.

60
Q

How do we push to a stack?

A

If space remains then append to the array, move the top spot in the array.

Else, report that we can’t add to the stack.

61
Q

How do we pop from a stack?

A

If there is something in the stack then remove from the end of the array, move the top spot in the array, return both success and the integer removed

62
Q

When a struct is passed as a parameter to a function, a copy of the whole struct is placed where?

A

The call stack

63
Q

What is a pass by reference?

A

Pass the location of the data in :main: to the functions rather than the data itself

64
Q

What is a pointer?

A

A data type that contains a memory address

65
Q

What do we use a pointer for?

A

To indirectly get to the values of variables

66
Q

What are the two values of pointers?

A

An address stored by the pointer

The value at the address where the pointer points

67
Q

When a pointer is declared, is the space also set aside?

A

no, the space must be declared separately

68
Q

The address stored in the pointer must assign what?

A

A memory address to the pointer

69
Q

What are the two options for function declarations in a C file?

A

Include all the code for a function before it is used

Define a prototype of the function at the top of the C file and then give the code later

70
Q

How do you compile with multiple C files in one gcc command?

A

gcc -o executable file1.c file2.c file3.

71
Q

How do we use a function from another file?

A

Put a prototype in its own file and use include ‘s in each c file that requires it.

72
Q

How do we read in an include file?

A

include “filename.h”