Week 2: C Fundamentals Flashcards

1
Q

What are the two main ways of changing programs to machine language?

A

Compilers and Interpreters

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

What is source code?

A

Code written in a programming language by a developer

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

What is a compiler?

A

A computer program that transforms code from one format to another (needs a different compiler depending on what system you are using)

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

What is an interpreter?

A

A program that translates and executes code, usually translates and executes source code line by line. There is no object code written as an intermediary

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

What is primary and secondary memory?

A

Primary memory: mechanism to present memory to the CPU, is temporary

Secondary memory: stores memory, is permanent

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

What is C?

A

A general purpose, procedural computer programming language supporting structured programming, lexical variable scope, and recursion, with a static type system

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

Who developed C?

A

Bell Labs: Ken Thompson, Dennis Ritchie, and others

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

Why was C originally developed?

A

To design and support Unix operating system

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

Benefits of C:

A
  • Intended as a language for programmers
  • Powerful and efficient
  • Structured
  • Standardized
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What three steps are necessary for a program to be executed?

A

Preprocessing, compiling, and linking

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

What is preprocessing?

A

Finds and deals with processing commands (directives) starting with a #

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

What is compiling?

A

Translating the program into machine instructions

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

What is linking?

A

Combining the object code produced by the compiler with any additional code needed to yield a complete executable program

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

What is the UNIX compile command and its syntax? (For C)

A

gcc

Syntax: { gcc -o nameOfExecutable program.c }

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

What are the three key language features of C?

A
  • Directives
  • Functions
  • Statements
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What do directives always begin with?

A

#

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

Do directives end with a semicolon or any other special marking?

A

NO

18
Q

What are directives?

A

Commands intended for the preprocessor

19
Q

What are functions?

A

A series of statements that have been grouped together and given a name

20
Q

What does a function end with

A

Usually a return statement

21
Q

What is the mandatory function?

A

main

22
Q

What should the main function return?

A

A status code, 0 indicates normal termination

23
Q

What is a statement?

A

A command to be executed when the code runs

24
Q

C requires each statement to end with a

A

; semicolon

25
Q

What are the two formats for comments?

A

/* comment */

or

// comment 
// more comment
26
Q

Each variable must have a

A

type

27
Q

All variables must be… before use

A

Declared

28
Q

When main declares variables, they must…

A

precede statements

29
Q

Variable initialization is also known as

A

Defining

30
Q

What does this do?

int height = 8, length = 12, width = 10;

A

Declares three ints and initializes them

31
Q

What does this do?

int height, length, width = 10;

A

Declares three ints but initializes only width

32
Q

Initializing a float requires what? Where?

A

an f at the end of the constant

profit = 2150.48f;

33
Q

Macro definitions are typically

A

define RECIPROCAL_OF_PI (1.0f / 3.14159f)

Containing only upper-case letters

34
Q

Identifiers (name for a variable) must

A

Begin with a letter or underscore

35
Q

Identifiers can contain:

A

Can contain letters, digits, and underscores ONLY

36
Q

Are identifiers case-sensitive?

A

Yes

37
Q

Keywords must:

A

contain only lowercase letters

38
Q

What are the steps for compiling a program?

A

Step 1: Write the source codes and header files

Step 2: Pre-process the source codes according to the preprocessor directives

Step 3: Compile the pre-processed source codes into object codes

Step 4: Link the compiled object codes with other object codes to produce the executable code

Step 5: Load the executable code into computer memory

Step 6: Run the executable code

39
Q

What is the syntax of a switch statement?

A

switch (input) {
case 1:
statement;
break;
case 2:
statement;
break;
default:
statement;
break;
}

Default is the equivalent of an “else”

40
Q

What is the difference between a while loop and a do-while loop?

A

While loops pre-test the condition

Do-while loops post test the condition

41
Q

What is the order of events in a for-loop?

A

a-b
c-b
c-b
c-b

42
Q

What is the format of the conditional ? operator

A

(condition) ? expression1 : expression2

If the condition evaluates to true, expression1 is executed, if the condition evaluates to false, expression2 is evaluated