Week 3: Compiler Directives, Data types, and Binary Representation Flashcards
What is cpp?
C preprocessor
What does the preprocessor do?
Creates a “new” version of your
program and it is this new program that actually gets
compiled
What is the format of the substitution Macro and what does it do?
define text1 text2
Tells the compiler to find all occurrences of “text1” in the source code and substitute “text2”.
What does the #undef … directive do?
Makes sure that defined(…) evaluates to false
What is the format of the include directive?
include
what does inline do?
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;
}
Can inline function improve the speed of your program?
Yes
Where are inline functions often defined?
In header (.h) files
What is the main difference between a #define statement and a function call if they look similar?
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 many bits is UTF-8? UTF-16? UTF-32?
8-bits, 16-bits, and 32-bits respectively
What does A start at in UTF-8? a?
A: 0100 0001
a: 0110 0001
What is 1s complement form?
Every negative number is simply the positive number with EVERY single digit flipped
All whole number integers are stored in either?
Magnitude only or 2s complement
How many bytes does a character take?
1 byte
How many bytes does a short take?
2 bytes
How many bytes does an int take?
4 bytes
How many bytes does a float take?
4 bytes
How many bytes does a double take?
8 bytes
What is a quad word?
8 bytes / 64 bits
What is the format of a character declaration / initialization
char a;
a = ‘g’;
OR
char a = ‘g’;
NOTE: single quotes
For a computer to perform an arithmetic operation, the operands must be
The same size (number of bits) and the same type
In C, if a variable must be converted to another type, what is the preference?
The computer will always convert to the more complex representation (variable promotion)
What is variable promotion?
Promoting to the more complex representation
What is implicit conversion?
When data types are upgraded to become the same type (the largest) automatically
What is explicit conversion?
The programmer forcing an expression to be of a specific type (type casting)
What is type casting?
The programmer forcing an expression to be of a specific type
What is the format of type casting?
(data_type)(expression);
Example: (int)x + 1;
Can type casting force a higher data type to a lower data type?
Yes
What are the two ways of making a boolean MACRO?
#define BOOL int and typedef int BOOL;
What does typedef do? Syntax?
Creates an alias for a type
typedef (known data type) (alias to be used instead of)
define max(a,b) ( (a) > (b) ? (a) : (b) )
What is the difference between the following?
#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 );
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);
/* Same as n= (( i++ )>( j )?( i++ ):( j )) */