C Functions (5-6) Flashcards
What 2 parts should every function have in C?
Every function in C should have a function prototype and a function definition.
What is the format for a function?
Example: double square(double x); //function prototype double double square (double x) { return x * x; }
What functions which do not return a value called?
Void functions do not return a value.
~~~
example:
void printDouble(double x)
{
printf(“The value is %f\n”, x);
return; //return is not strictly required but it’s good practice.
}
~~~
In C, four memory segments might be used. What are they and when might they be used?
Code segment:
* The space used to store program instructions.
Static:
* The space used to store global and static variables
* This segment can be further classified into read only area and read write area.
Stack:
* Area of the memory that contains the program stack.
* A Last in First Out structure.
* Automatic variables (local variables and function arguments)
Heap
* An area of the memory used for dynamic runtime allocation.
What are static variables initialized to?
Static variables are initialized to zero automatically.
When does static allocation happen?
Static allocation happens before main starts.