Week 7: Function Calls in C, Variables (Scope) in C, Program Organization, and Header Files Flashcards
The “STACK” is what?
The stack is the memory set aside as scratch space for a thread of execution. Reserved for each function call
When calling a function, each parameter must…
Reduce down to a single value
What is the difference between pass-by-reference and pass-by-value?
pass-by-reference means passing a variable by its location in memory, which allows a variable to be changed by a function
pass-by-value means literally passing he value stored in the variable with no way of changing the variable stored in main memory
When accessing an array, using the name of the array is essentially….
Using the location in memory of the first item in the array
dbray &(dbray[0]) both mean…
The address of the first element of the array
Arrays are actually…
Pointers
double *ptr = &(array[0]);
is the same as….
double *ptr = array;
The main difference between malloc and calloc is…
Malloc sets aside a certain number of bytes:
double *a;
a = ( double *) malloc (40);
Calloc sets aside a certain number of that type
double *a;
a = (double *) calloc ( 70, sizeof(double) );
Static memory is ____ at the end of each use.
Dynamic memory is ______ at the end of each use unless ____
Static memory is deallocated at the end of each use.
Dynamic memory is not deallocated at the end of each use unless freed
How do you free the following dynamic memory?
double *a;
a = ( double *) malloc (40);
free(a)
Two ways of causing a memory leak are….
Not freeing the memory with free()
Reassigning the pointer variable to another place in dynamic memory before freeing it with free()
What lines of code are required to set aside 70 double variables? Using malloc? Calloc? Calloc another way?
double *a;
a = (double)malloc(708);
or
a = (double)malloc(70(sizeof(double)));
or
a = (double)malloc(708);
or
a = (double *) calloc ( 70, sizeof(double) );
What does a function prototype do?
Tell the preprocessor what to expect as a return type
What is the format of a function protoytype?
float division(int , int , int* , int*);
Function prototypes MUST
End with a semicolon