Topic 2 - C Fundamentals Flashcards

(57 cards)

1
Q

Sime C programs have the form:

A
directives
int main(void)
{
   statements
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Every C program relies on 3 key language features:

A

1) Directives
2) Functions
3) Statements

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

Before a program can be executed, three steps are usually necessary:

A

1) Preprocessing
2) Compiling
3) Linking

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

Define: Preprocessing:

A

The preprocessor obeys commands that begin with # (known as directives)

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

Define: Compiling:

A

A compiler translates the program into machine instructions (object code)

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

Define: Linking

A

A linker combines 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
7
Q

Compiling and Linking: The _____ and _____ are usually integrated within the _____.

A

preprocessor; linker; compiler.

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

With filenames for C, is the .c extension required or not.

A

Required

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

To compile and link a program called pun.c under Unix, enter the following command in a terminal at command-line promo:

A

cc pun.c

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

What is automatically done when “cc” is invoked?

A

Preprocessing and linking are automatic when using cc.

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

After compiling and linking the program, what happens?

A

cc leaves the executable program in a file named a.out by default

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

What does -o option do

A

choose the name of the file containing the executable program

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

Give the command to choose the name “pun” for the output file when you compile the program pun.c

A

cc -o pun pun.c
or
cc pun.c -o pun

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

What happens before a C program is compiled?

A

It is first edited by a preprocessor.

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

Commands intended fro the preprocessor are called ______

A

Directives

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

What character do directives start with?

A

A hashtag (#) character

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

Examples of directives:

A

include

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

What is

A

A header containing information aboutC’s standard I/O library

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

By default, each directive is how many lines long?

A

One line long

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

Are there any semicolons besides directives?

A

No and no other special marker at the end either

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

What is a function?

A

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

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

A function that computes a value uses a____

A

return statement to specify what value it returns

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

What gets called automatically when a C program you’ve made is executed?

A

The Main function

24
Q

What does the main return?

A

A Status code

25
Is the status code that's retuned by a Unix shell script similar to the status code retuned by a Unix shells script?
Yes
26
What is the status code returned by main when a program normally terminates after finishing?
0
27
Will you run into problems if there's no return statement at end of main function?
Yes, warning message.
28
When printing strings with printf function, does the curse automatically advance the cursor one line?
No, you have to include the \n in the string to be printed
29
How do you comment?
/* and ends with */
30
Variables must be ______ before they are used.
Declared
31
Can several variables be declared at the same time?
Yes: | int height, length, width, volume
32
In C99, how can you comment?
// this is a commend ended at the end of the line
33
When main function contains declarations, where must they be placed?
Must precede ANY statements.
34
In C99, declarations don't have to come before statements
Yet, variable must be declared before they are used
35
Can you assign value of certain type into a variable of a different type?
It is possible but not always safe.
36
Explain the different parts to this statement: | printf ( "Height: %d\n", height );
- printf is being used to display the current value of a variable - %d is a placeholder indicating where the value of the variable height is to be filled in
37
What type of variables does %d work on?
only int variables
38
How do you print float variables since you cannot use %d with float?
Use %f instead.
39
%f prints how many decimals?
6 decimals.
40
profit = 2150.48f; printf("Profit: $ \n", profit); What goes in the space to print only 2 decimals of the profit value instead of 6?
%.2f
41
Can an initial value of a variable be included in its declaration?
Yes, called the "initializer" ex: int height = 8, length = 12, width = 10; int height, length, width = 10;
42
How do you scan an int value stored in variable "i"?
scant ("%d", &i)
43
How do you scan a float value stored in variable "x"?
scanf("%f", &x);
44
What are macro definitions?
``` Name a constant - ex: #define INCHES_PER_POUND 166 ```
45
When a program is compiled, what is replacing each macro by the value it represents?
The Preprocessor
46
Duringpreprocessing,thestatement weight = (volume + INCHES_PER_POUND - 1) / INCHES_PER_POUND; will become
weight = (volume + 166 - 1) / 166;
47
Names for variables, functions, macros, and other entities are called _____
identifiers
48
identifiers must being with a
letter or underscore (i.e. no numbers)
49
Is C case-sensitive?
Yes
50
What is the limit on the maximum length of an identifier?
C places no limit; none.
51
The following keywords can't be used as identifiers:
``` auto enum restrict unsigned break extern return void case float char for const goto continue if default inline struct _Imaginary do int switch double long typedef else register union short signed sizeof static volatile while ```
52
The following keywords can't be used as identifiers (C99 only):
inline; restrict; _Bool; _Complex; _Imaginary
53
A c program is a series of _____
tokens
54
Give examples of tokens:
``` - identifiers keywords operators punctuations constants string literals ```
55
How many tokens are in: | printf("Height: %d\n", height);
``` 7: printf - identifier ( - punctuation "Height: %d\n" - string literal , - punctuation height - identifier ) - punctuation ; - punctuation ```
56
How important is the amount of space between tokens usually?
Usually not critical.
57
Can you put a new-line character in a string over two lines?
No its illegal