C Flashcards

(40 cards)

1
Q

What are C programs are compiled into?

A

Object code.

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

What is gcc?

A

The GNU Compiler Collection is an open source C compiler.

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

What is the default executable name produced by gcc?

A

a.out

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

How can you specify the executable name produced by gcc?

A

Using the -o switch.

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

What does cpp stand for?

A

cpp is the C preprocessor.

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

When does cpp examine source code, relative to compilation?

A

Source code is examined by cpp prior to compilation.

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

cpp must be called separately from gcc.

A

False, gcc calls cpp automatically.

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

What does the following line do?
cpp hello.c

A

By default, independent invocations of cpp prints the rewritten source code to the screen.

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

How are cpp directives distinguished from regular C code?

A

A leading # symbol.

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

Macros are pure textual substitutions, typically used for defining what 2 things?

A

Constants, and very simple functions in compact form.

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

What would occur if gcc encountered a #include directive?

A

It would produce an invalid error syntax.

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

In what way are standard header files included differently than user defined header files?

A

Using <file>, instead of “path”.

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

Why is no additional path information included with standard header file names?

A

Because these are located in pre-defined folders that cpp and the compiler will always search.

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

Can operating systems or platforms define their own standard header files?

A

Yes.

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

What about the C compilation process makes header files necessary?

A

C compilation is a line by line process that will generate errors if a not previously defined identifier is encountered.

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

Source files are compiled interdependently.

A

False, they are compiled independently, which further reinforces the need for header files.

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

Which compiler error is commonly associated with the omission of a header file?

A

“Symbol could not be resolved.”

18
Q

The C library is big, relative to other languages.

19
Q

%i can be used in place of %d to specify an integer.

20
Q

Which format specifier is used for pointers?

21
Q

What should be used in place of printf() for displaying error/warnings?

A

fprintf(stderr, message, var_list);

22
Q

Why should fprintf() be used in place of printf() for displaying errors?

A

Because fprintf() allows specification of output stream, and stderr is unbuffered (usually prints immediately).

23
Q

NULL is a keyword in C.

A

False - NULL is a macro defined in several standard C headers.

24
Q

How can NULL be defined as a macro?

A

#define NULL ((void *)0)

25
Are C functions pass by value, reference, or both?
Pass by value.
26
If int \*p1 = arr; int \*p2 = arr + 4; and and ints are 4 bytes, what does int x = (char\*)p2 - (char\*)p1 equal?
16
27
Will the following line compile, if p is of type (char*) and stdio.h is included? printf(p);
Yes, but a warning will be generated.
28
If char *p = "hi"; what does printf(p + 1); do?
Outputs "i" to standard output.
29
Which ASCII character proceeds each string in C?
The null character '\0', which is ASCII value 0. It isn't printable.
30
If char c = '\0'; what does (c == NULL) return?
Compiler issues a warning, as you'd be comparing a character with a pointer.
31
The following is a valid way of obtaining the number of elements in arr: int arr[] = {1, 2, 3, 4}; int size = sizeof(arr)/sizeof(arr[0]);
True.
32
Where does the following code produce a compile error? int a = 1; void *p = (int *)&a; printf("%d", *p);
Line 3, because a void pointer cannot be dereferenced.
33
If p is of type (int \*), what's the difference between the following two bits of code? ++\*p \*++p
The first adds 1 to the integer p points to, the second returns the number held by the location adjacent to p.
34
Declare (but don't initialize) two integer pointers in 1 line.
int *p1, *p2;
35
What does the following print? int array[5][5]; printf("%d", ((array == \*array) && (\*array == array[0])));
1
36
What's the difference between big endian and little endian?
In little endian, the least significant value is stored first, whereas in big endian, the most significant value is stored first.
37
Faster access to non-local variables is achieved using an array of pointers to activation records, called a..?
Activation tree.
38
What does the following declare? int * f[ ] ()
An array of functions returning pointers to integers.
39
A reference can never be NULL.
True.
40
What does the following declare? int (*f())[ ]
int (*f())[ ] declares a function returning a pointer to an array of integers.