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?

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?

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
What are the two formats for comments?
/\* comment \*/ or ``` // comment // more comment ```
26
Each variable must have a
type
27
All variables must be... before use
Declared
28
When main declares variables, they must...
precede statements
29
Variable initialization is also known as
Defining
30
What does this do? int height = 8, length = 12, width = 10;
Declares three ints and initializes them
31
What does this do? int height, length, width = 10;
Declares three ints but initializes only width
32
Initializing a float requires what? Where?
an f at the end of the constant profit = 2150.48f;
33
Macro definitions are typically
Containing only upper-case letters #define RECIPROCAL\_OF\_PI (1.0f / 3.14159f)
34
Identifiers (name for a variable) must
Begin with a letter or underscore
35
Identifiers can contain:
Can contain letters, digits, and underscores ONLY
36
Are identifiers case-sensitive?
Yes
37
Keywords must:
contain only lowercase letters
38
What are the steps for compiling a program?
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
What is the syntax of a switch statement?
switch (input) { case 1: statement; break; case 2: statement; break; default: statement; break; } Default is the equivalent of an "else"
40
What is the difference between a while loop and a do-while loop?
While loops pre-test the condition Do-while loops post test the condition
41
What is the order of events in a for-loop?
a-b c-b c-b c-b
42
What is the format of the conditional ? operator
(condition) ? expression1 : expression2 If the condition evaluates to true, expression1 is executed, if the condition evaluates to false, expression2 is evaluated