C Programming 03 Flashcards
1
Q
What does the ? operator provide?
A
Can be used for a shorthand for if-else in an expression.
e.g
condition ? expression if true : expression if false;
or
max = (a > b) ? a : b;
2
Q
How is a string represented in C?
A
An array of chars terminated by the NULL character ‘\0’
Compiler adds 0 at end of array so make length of array big enough
3
Q
What is #ifdef?
A
A preprocessor directive which include some code only if a symbol is defined e.g #ifdef X .. #else .. #endif
4
Q
Why use macro functions?
A
- Don’t need to worry about types
* Useful for things which aren’t valid code
5
Q
What is a header guard?
A
#ifndef POINT_H_ #define POINT_H_ typedef struct { int x, y } point; #endif