Pointers and Functions Flashcards
Where are variable names stored?
Symbol table, not memory
*a_ptr++. What happens?
++ has higher precedence than * so it will increment the pointer before dereferencing it.
a_ptr++ or a_ptr–, how much is the pointer incremented/decremented by?
By the byte size of the data it points to
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?
An int is 4 bytes, a double is 8 bytes. So it will only print the first 4 bytes.
What is a function prototype?
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.
What is the scope rule?
Local parameters and variables are only accessible inside the function.
What happens in the stack and memory when a function is called and after it has finished?
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.