C Flashcards

1
Q

Variable Argument Lists:

  • signature
  • usage
  • caveats
A
signature: int foo(type bar, ...)
The ... indicates variable argument list. At least one type is required to preceed (as its used with stack magic to make this work)
usage: 
int foo(const char* format, ...) {
va_list list; // declare the va type
va_start(list, format); // pass in va_list and preceeding type, this initializes things
type a = va_arg(list, type); // grabs the next item casting to desired type
caveats: you have to know how many arguments there will be. It uses stack magic.
#include
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

char, short, long, long long

int can be short or long

A

8bits, 16bits, 32bits, 64bits

int is typically 32bits

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

VLA (Variable Length Array)

A

As of C99
Array sized at runtime, via variable arguments, allocated on the stack.
int array[x][y];

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