Pointers and Functions Flashcards

1
Q

Where are variable names stored?

A

Symbol table, not memory

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

*a_ptr++. What happens?

A

++ has higher precedence than * so it will increment the pointer before dereferencing it.

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

a_ptr++ or a_ptr–, how much is the pointer incremented/decremented by?

A

By the byte size of the data it points to

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

If a pointer initially refers to an int, then let’s say we increment it by some number, then now it points to a double. When we dereference it, what would it output?

A

An int is 4 bytes, a double is 8 bytes. So it will only print the first 4 bytes.

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

What is a function prototype?

A

Need to declare function prototypes before main() function for other functions which will be used in main as other functions are supposed to be defined under main() but C does not recognize the function if no prototype is given. Include the return type, name, and data type of parameter. Name of parameter(s) is optional.

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

What is the scope rule?

A

Local parameters and variables are only accessible inside the function.

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

What happens in the stack and memory when a function is called and after it has finished?

A

An activation record is created in the stack and memory is allocated for formal parameters and local variables of the function. Once the function is done executing, this is released. Hence, local parameters and variables are only accessible during the execution of a function.
They are called automatic variables.

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