C Functions (5-6) Flashcards

1
Q

What 2 parts should every function have in C?

A

Every function in C should have a function prototype and a function definition.

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

What is the format for a function?

A
Example:
double square(double x); //function prototype
double 

double square (double x)
{
return x * x;
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What functions which do not return a value called?

A

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.
}
~~~

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

In C, four memory segments might be used. What are they and when might they be used?

A

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.

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

What are static variables initialized to?

A

Static variables are initialized to zero automatically.

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

When does static allocation happen?

A

Static allocation happens before main starts.

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