Week 3: Compiler Directives, Data types, and Binary Representation Flashcards

1
Q

What is cpp?

A

C preprocessor

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

What does the preprocessor do?

A

Creates a “new” version of your
program and it is this new program that actually gets
compiled

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

What is the format of the substitution Macro and what does it do?

A

define text1 text2

Tells the compiler to find all occurrences of “text1” in the source code and substitute “text2”.

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

What does the #undef … directive do?

A

Makes sure that defined(…) evaluates to false

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

What is the format of the include directive?

A

include

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

what does inline do?

A

When the compiler compiles your program, it will not compile it as a function. Rather, it just integrates the necessary code:
ex:

inline int max(int a, int b) {
return a>b?a:b;
}

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

Can inline function improve the speed of your program?

A

Yes

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

Where are inline functions often defined?

A

In header (.h) files

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

What is the main difference between a #define statement and a function call if they look similar?

A

define will run until completion until every variable is incremented (even post incrementation like “i++”)

A function call of similar type will return before the post incrementation

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

How many bits is UTF-8? UTF-16? UTF-32?

A

8-bits, 16-bits, and 32-bits respectively

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

What does A start at in UTF-8? a?

A

A: 0100 0001
a: 0110 0001

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

What is 1s complement form?

A

Every negative number is simply the positive number with EVERY single digit flipped

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

All whole number integers are stored in either?

A

Magnitude only or 2s complement

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

How many bytes does a character take?

A

1 byte

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

How many bytes does a short take?

A

2 bytes

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

How many bytes does an int take?

A

4 bytes

17
Q

How many bytes does a float take?

A

4 bytes

18
Q

How many bytes does a double take?

A

8 bytes

19
Q

What is a quad word?

A

8 bytes / 64 bits

20
Q

What is the format of a character declaration / initialization

A

char a;
a = ‘g’;

OR

char a = ‘g’;

NOTE: single quotes

21
Q

For a computer to perform an arithmetic operation, the operands must be

A

The same size (number of bits) and the same type

22
Q

In C, if a variable must be converted to another type, what is the preference?

A

The computer will always convert to the more complex representation (variable promotion)

23
Q

What is variable promotion?

A

Promoting to the more complex representation

24
Q

What is implicit conversion?

A

When data types are upgraded to become the same type (the largest) automatically

25
Q

What is explicit conversion?

A

The programmer forcing an expression to be of a specific type (type casting)

26
Q

What is type casting?

A

The programmer forcing an expression to be of a specific type

27
Q

What is the format of type casting?

A

(data_type)(expression);

Example: (int)x + 1;

28
Q

Can type casting force a higher data type to a lower data type?

A

Yes

29
Q

What are the two ways of making a boolean MACRO?

A
#define BOOL int
      and
typedef int BOOL;
30
Q

What does typedef do? Syntax?

A

Creates an alias for a type

typedef (known data type) (alias to be used instead of)

31
Q

define max(a,b) ( (a) > (b) ? (a) : (b) )

What is the difference between the following?

A
#define max(a,b) ( (a) > (b) ? (a) : (b) )
is seen as:
printf("%d", 2 * ( (3+3) > (7) ? (3+3) : (7) );
#define max(a,b) a>b?a:b
is see as:
printf("%d", 2 * 3+3 > 7 ? 3+3 : 7 );
32
Q
If there is a macro directive like so:
#define max(x,y) ((x)>(y)?(x):(y))

What does the preprocessor see with the following input:
n= max( i++, j);

A

/* Same as n= (( i++ )>( j )?( i++ ):( j )) */