03 - Functions Flashcards
Functions in C are most like what in Java?
- Static methods
- Public methods
- Private methods
Static methods
How many options can an ‘‘if’ statement choose between?
2
More conditions can be used by breaking them down into two compound conditions.
e.g. if ((x || y) && z){}
What will be the final value of ‘x’ after the following code?
int x = -1; if(x){ x = 1 } else { x = 2 }
x = 1
An if statement will count any non-zero value as true
What is a function prototype?
A function prototype is a way of declaring a function without its body. It simply lets the program know that the function exists, allowing the compiler to check its use, without knowing what it actually calculates/outputs
Is this a valid function prototype?
int add(int, int);
Yes
It’s not necessary to give names to the arguments - just their types.
Which of these are you not likely to find in a header file?
- Function prototypes
- Macro definitions
- Function definitions
- Constant variable declarations
Function definitions
These cannot be included in a header file that is intended to be used in more than one C file, as a function can only be defined once in the entire program
What happens if you use a function without declaring it first?
C will guess a prototype, based on how it has been called.
It will assume the function returns an integer, and will guess the argument types based on what you have provided