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;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Why use macro functions?

A
  • Don’t need to worry about types

* Useful for things which aren’t valid code

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

What is a header guard?

A
#ifndef POINT_H_
#define POINT_H_
typedef struct { int x, y } point;
#endif
How well did you know this?
1
Not at all
2
3
4
5
Perfectly