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
Where is the stack frame added once a function is called?
The call stack
26
What does a stack frame contain?
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
27
What happens when the function ends?
The stack frame for the function is removed from the call stack, so all the information disappears.
28
What is always bottom of the stack?
Main local variables
29
What data type of a single character?
A char data type
30
Is a single character a byte?
Yes!
31
Does char hold unicode values?
no, it is treated as a byte (number
32
What is \n?
Carriage return
33
What is \r?
Line feed
34
What is \r used for?
Network protocols
35
Wat is \t?
Tab character
36
What is a C string?
C strings are arrays of characters
37
How do you identify the end of a string?
With a NULL character?
38
How do you assign, compare, copy or work on strings?
Using a string library to do the work
39
What is argc?
Argument count: the number of strings in the list of parameters
40
What is argv?
Argument values- the strings passed to the program
41
How do we manage arguments?
Main is always provided with at least one argument: the name of the program when it was invokved
42
How does the name of the program appear?
Always appears as argh[0]
43
Typical steps for a main function?
Set up default values for parameters Loop through all of arg v to store parameters updates get on with the typical work
44
How do you include a C string library?
#include
45
What does strlen do?
Return the number of characters in the string
46
Is strcmp safe or unsafe?
unsafe
47
What is the printing pattern for a double?
%f
48
What is the printing value for a char?
%c
49
For signed data, what bit identifies whether the data is positive or negative?
The leftmost bit
50
What does the const modifier do
Flag that this variables value shouldn't change after initialization Often used in parameter declarations
51
What does the static modifier do?
For a local variable, ask for its space to be somewhere other than the stack so the value survives across function invocations
52
Type coercions go in one direction? True or False
True
53
What does the command typedef do?
Lets you give a different name to existing commands
54
What are three ways to create your own data types?
- Struct - Enum - Union
55
Which two data type creation methods can nest within one another?
Structs and unions
56
Where can an enum appear?
Inside a struct or a union
57
What is the structure of a typedef?
typedef struct { float x; float y; } point; point p; p. x = 5 p. y = 10.5
58
How do you initialize a stack?
- Set the stack to have no entries - Store the size of the stack - Return whether or not the initialization is successful
59
How do you destroy a stack?
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
How do we push to a stack?
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
How do we pop from a stack?
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
When a struct is passed as a parameter to a function, a copy of the whole struct is placed where?
The call stack
63
What is a pass by reference?
Pass the location of the data in :main: to the functions rather than the data itself
64
What is a pointer?
A data type that contains a memory address
65
What do we use a pointer for?
To indirectly get to the values of variables
66
What are the two values of pointers?
An address stored by the pointer The value at the address where the pointer points
67
When a pointer is declared, is the space also set aside?
no, the space must be declared separately
68
The address stored in the pointer must assign what?
A memory address to the pointer
69
What are the two options for function declarations in a C file?
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
How do you compile with multiple C files in one gcc command?
gcc -o executable file1.c file2.c file3.
71
How do we use a function from another file?
Put a prototype in its own file and use include 's in each c file that requires it.
72
How do we read in an include file?
#include "filename.h"