Lecture 7: Structures Flashcards

1
Q

A good location to leave structures is…

A

at the top of your files (or in header files).

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

Defining a structure

A

tells the compiler about the new type, but doesn’t allocate storage.

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

Declaring a variable

A

tells the compiler the type and identifier (name) you chose.

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

What happens when you pass a structure to a function?

A

It is passed by value.

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

Ways to assign values to struct

A

struct example name = { a, b, c }; // Bad practice. Don’t.
struct example name = { .x = a, .y = b, .z = c } // Much better.
struct example name = { .x = a }; // y and z uninitialized.

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

Compound literals.

A

name = (struct example) { .x = a, .y = b, .z = c };
This is used to assign a value to something already declared. Or, you can just set piece by piece.

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

Arrays of structs

A

struct example[] = { {.x = a}, {.x = b} };
struct example[] = { [0].x = a, [1].x=b }

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

Can structs contain other structs?

A

Yes.

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

Can you define a structure without a name?

A

You could. But it’s not recommended.
I.e.
struct
{
// stuff goes here
} arr_of_these[n];

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

go back to slides and find information about memory. the stack. etc

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

What operations are allowed for the stack?

A

“push” and “pop”. Add an element to the top, or remove it.

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

What happens to memory when a function is called?

A

An entry is pushed onto the stack, containing arguments, space for variables in the function, and a return address.

Stack grows when a function is called and shrinks as it returns. It grows from wherever it is.

Note: in gdb, bt will show the contents of the stack. Alternatively, bt –full

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

notes on processes

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