Topic 2 - C Fundamentals Flashcards

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
Q

Is the status code that’s retuned by a Unix shell script similar to the status code retuned by a Unix shells script?

A

Yes

26
Q

What is the status code returned by main when a program normally terminates after finishing?

A

0

27
Q

Will you run into problems if there’s no return statement at end of main function?

A

Yes, warning message.

28
Q

When printing strings with printf function, does the curse automatically advance the cursor one line?

A

No, you have to include the \n in the string to be printed

29
Q

How do you comment?

A

/* and ends with */

30
Q

Variables must be ______ before they are used.

A

Declared

31
Q

Can several variables be declared at the same time?

A

Yes:

int height, length, width, volume

32
Q

In C99, how can you comment?

A

// this is a commend ended at the end of the line

33
Q

When main function contains declarations, where must they be placed?

A

Must precede ANY statements.

34
Q

In C99, declarations don’t have to come before statements

A

Yet, variable must be declared before they are used

35
Q

Can you assign value of certain type into a variable of a different type?

A

It is possible but not always safe.

36
Q

Explain the different parts to this statement:

printf ( “Height: %d\n”, height );

A
  • 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
Q

What type of variables does %d work on?

A

only int variables

38
Q

How do you print float variables since you cannot use %d with float?

A

Use %f instead.

39
Q

%f prints how many decimals?

A

6 decimals.

40
Q

profit = 2150.48f;
printf(“Profit: $ \n”, profit);
What goes in the space to print only 2 decimals of the profit value instead of 6?

A

%.2f

41
Q

Can an initial value of a variable be included in its declaration?

A

Yes, called the “initializer” ex:
int height = 8, length = 12, width = 10;
int height, length, width = 10;

42
Q

How do you scan an int value stored in variable “i”?

A

scant (“%d”, &i)

43
Q

How do you scan a float value stored in variable “x”?

A

scanf(“%f”, &x);

44
Q

What are macro definitions?

A
Name a constant - ex:
#define INCHES_PER_POUND 166
45
Q

When a program is compiled, what is replacing each macro by the value it represents?

A

The Preprocessor

46
Q

Duringpreprocessing,thestatement
weight = (volume + INCHES_PER_POUND - 1) / INCHES_PER_POUND;
will become

A

weight = (volume + 166 - 1) / 166;

47
Q

Names for variables, functions, macros, and other entities are called _____

A

identifiers

48
Q

identifiers must being with a

A

letter or underscore (i.e. no numbers)

49
Q

Is C case-sensitive?

A

Yes

50
Q

What is the limit on the maximum length of an identifier?

A

C places no limit; none.

51
Q

The following keywords can’t be used as identifiers:

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

The following keywords can’t be used as identifiers (C99 only):

A

inline; restrict; _Bool; _Complex; _Imaginary

53
Q

A c program is a series of _____

A

tokens

54
Q

Give examples of tokens:

A
- identifiers
keywords
operators
punctuations
constants
string literals
55
Q

How many tokens are in:

printf(“Height: %d\n”, height);

A
7:
printf - identifier
( - punctuation
"Height: %d\n" - string literal
, - punctuation
height - identifier
) - punctuation
; - punctuation
56
Q

How important is the amount of space between tokens usually?

A

Usually not critical.

57
Q

Can you put a new-line character in a string over two lines?

A

No its illegal