C - Hello, World Flashcards

1
Q

What are the 3 general steps in creating an executable?

A
  1. Preprocessing
  2. Compiling
  3. Linking
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is preprocessing?

A

Before code is compiled it is given to a program called the preprocessor. The preprocessor edits and manipulates code, setting it up for the compiler. Typically the preprocessor looks for lines that begin with # and alters the code based on these directives.

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

What is compiling?

A

Preprocessed code is given to the compiler, a program that translates C statements into machine instructions.

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

What is linking?

A

A linker combines the object code produced by the compiler with any additional code needed to create a complete execuatable. This additional code includes things like library functions.

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

What are the three fundamental language features that C relies on?

A
  1. Directives
  2. Fuctions
  3. Statements
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is a function?

A

A series of statements grouped together and given a name

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

What does main return?

A

An integer status code

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

How do you start all c programs?

A

include

int main(void)

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

Why include a header file in a C program?

A

to use standard libraries

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

What are the steps for building C programs?

A

preprocessing, compiling, linking. (Using gcc usually executes all three steps automatically.)
in console:
>gcc -o hello hello.c
>./hello

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

What is pre-processing?

A

Pre-processing: processing directives,
modifying source file text

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

What is compiling?

A

Compiling: translating source code into
machine instructions (object code)

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

What is linking?

A

Linking: combining object code created
by compiler with other code to create a
single executable program

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

What are comments?

A

They are text for documentation purposes and are mapped to whitespaces before preprocessing. (Neither pre-processor nor compiler sees them.)

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

What is a variable

A

it has a name, a type and a value. It can be assigned values, do calculations and in-/output variable

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

What are control structures in C?

A

Two types:
 Selection
* if statement
* switch statement
 Loops
* while loop
* do while loop
* for loop

17
Q

What does the Pre-processor do?

A

Removes comments
Modifies source code
according to preprocessor directives
Most importantly:
includes header files into
source code

18
Q

What are the steps to compiling a program in C?

A

Step 1: Pre-Processor. Removes comments, reads pre-directives, includes header files. Output: Translation Unit,
Step 2: Compiler. Performs correctness checks, code optimizations. Output: assembler code (.s file),
Step 3: Assembler. Translates assembler code (.s file) into binary machine instructions/object code (.o file),
Step 4: Linker. Combines multiple object files into a single file, Output: exe file.

19
Q

What is the use of a header guard in preprocessing?

A

Use: to avoid including a header file more than once, check if it has already been included.
Ex:
grandparent.c
#ifndef GRANDPARENT_H
#define GRANDPARENT_H
struct foo{
int member;
};
#endif
….
in parent.c
#ifndef PARENT_H
#define PARENT_H
#include “grandparent.h”
#endif

20
Q

What is the difference between variable definition and declaration?

A

Variable declarations can be duplicated, have static name type binding done at compile time and specifiy identifier and type.

Variable definition: only one allowed, assigns fixed address to variable (at runtime?).

Definition and declaration of VARIABLE looks the same, possible: int a; but not so for functions.

21
Q

What is initialization of a variable?

A

Initialization: assigns initial value to a variable, value not needed at compile time. Assigns scope-

22
Q

What is scope?

A

Scope is the portion of program where name of variable (identifier) can be used to refer to a variable.

23
Q

How to compile a file world.c in both gcc and clang?

A

gcc world.c -std =c90

clang world,c -std=c99

24
Q

what are the different compiler options and what are their uses?

A

The different compiler options are

-o: Name your executable
-g: Add in debugging information
-Wall: Give warnings
-Wextra: Give additional warnings
-O, O2, O3: Compiler optimization and different levels of it.

25
Q

What are relational operators?

A

A binary operator that tests a relationship between two entities and produces true or false:

, <=, >=

26
Q

What is an equality operator?

A

A binary operator that tests equality or lack of equality between two entities:

!=

27
Q

Variables always have a type.

A

Syntax:
type var_name;

Example:
char c;
int n;

28
Q

Logical operators
|| OR, && AND, ! NOT

A

expression1 || expression2 - if one of the 2 expressions is true, then the whole expression is true

expression1 && expression2 - if one of the 2 expressions is false, then the whole expression is false

!expression - if the expression is false, then the whole expression is true. If the
expression is true, then the whole expression is false.

The value of the whole expression is 0 if false, something else if true

29
Q

Comparisons

A

< Less than
<= Less or equal to
== Equal to
>= Greater or equal
to
> Greater than
!= Different than

30
Q

expression operator expressionExamples:
(a + 32) < 98
b == a
c >= f () + 402

A

The value of a comparison is 0 if false, and
something else if true.