basic C Flashcards
True or False: printf() is a C library function, not a construct of the language.
True. printf() comes from the <stdio.h> library, which is a C standard library.</stdio.h>
True or False: #include is a preprocessor directive.
True. #include gets handled by the C preprocessor
What kind of file gets passed into the C preprocessor? What does it do?
The preprocessor processes the macros of a .c file and outputs another .c file. (#define, #include)
(gcc -E)
What does the C compiler do? Input file -> Output file?
The compiler takes the .c file given by the preprocessor and gives a .s assembly file.
(gcc -S)
What does the assembler do? Input -> Output file?
The assembler processes the .s assembly file into a .o binary object file.
(gcc -c)
What does the linker do?
Combines the .o object file w/ necessary libraries and creates an executable. (a.out)
(gcc -o)
True or False: a.out can be run as a command and the operating system will load those instructions into memory and execute them.
True. The entry point is the main function.
True or False: C is compiled the same way in every machine
False. Unlike Java, the machine code C gets compiled into varies on the OS used.
C is weakly typed. What does that mean?
You can cast a value to anything without error, such as from char* to long. It will attempt to convert it but will only issue a warning. This is called coercion. DO NOT DO THIS.
Which is an example of implicit and explicit conversion?
(A)
int a = 4;
char b = ‘c’;
printf(a+b);
(B)
int i; float f1;
i = (int) f2;
(A) implicit
(B) explicit
What is the scope of variable
x? Variable y? Variable z?
int y;
static int z;
int add(int a, int b) {
int x = a+b;
return x;
}
x: Local scope
y: global scope / global
lifetime (storage class static)
z: local scope / global lifetime
“Variables defined outside any function have global
lifetime (storage class static), but not might not
have global scope (if explicitly declared static)”