basic C Flashcards

1
Q

True or False: printf() is a C library function, not a construct of the language.

A

True. printf() comes from the <stdio.h> library, which is a C standard library.</stdio.h>

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

True or False: #include is a preprocessor directive.

A

True. #include gets handled by the C preprocessor

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

What kind of file gets passed into the C preprocessor? What does it do?

A

The preprocessor processes the macros of a .c file and outputs another .c file. (#define, #include)
(gcc -E)

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

What does the C compiler do? Input file -> Output file?

A

The compiler takes the .c file given by the preprocessor and gives a .s assembly file.
(gcc -S)

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

What does the assembler do? Input -> Output file?

A

The assembler processes the .s assembly file into a .o binary object file.
(gcc -c)

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

What does the linker do?

A

Combines the .o object file w/ necessary libraries and creates an executable. (a.out)
(gcc -o)

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

True or False: a.out can be run as a command and the operating system will load those instructions into memory and execute them.

A

True. The entry point is the main function.

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

True or False: C is compiled the same way in every machine

A

False. Unlike Java, the machine code C gets compiled into varies on the OS used.

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

C is weakly typed. What does that mean?

A

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.

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

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

(A) implicit
(B) explicit

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

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;
}

A

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)”

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