C Flashcards

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.

A

False.

19
Q

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

A

True.

20
Q

Which format specifier is used for pointers?

A

%p

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
Q

Are C functions pass by value, reference, or both?

A

Pass by value.

26
Q

If int *p1 = arr; int *p2 = arr + 4; and and ints are 4 bytes, what does int x = (char*)p2 - (char*)p1 equal?

A

16

27
Q

Will the following line compile, if p is of type (char*) and stdio.h is included?
printf(p);

A

Yes, but a warning will be generated.

28
Q

If char *p = “hi”; what does printf(p + 1); do?

A

Outputs “i” to standard output.

29
Q

Which ASCII character proceeds each string in C?

A

The null character ‘\0’, which is ASCII value 0. It isn’t printable.

30
Q

If char c = ‘\0’; what does (c == NULL) return?

A

Compiler issues a warning, as you’d be comparing a character with a pointer.

31
Q

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]);

A

True.

32
Q

Where does the following code produce a compile error?
int a = 1;
void *p = (int *)&a;
printf(“%d”, *p);

A

Line 3, because a void pointer cannot be dereferenced.

33
Q

If p is of type (int *), what’s the difference between the following two bits of code?
++*p
*++p

A

The first adds 1 to the integer p points to, the second returns the number held by the location adjacent to p.

34
Q

Declare (but don’t initialize) two integer pointers in 1 line.

A

int *p1, *p2;

35
Q

What does the following print?
int array[5][5];
printf(“%d”, ((array == *array) && (*array == array[0])));

A

1

36
Q

What’s the difference between big endian and little endian?

A

In little endian, the least significant value is stored first, whereas in big endian, the most significant value is stored first.

37
Q

Faster access to non-local variables is achieved using an array of pointers to activation records, called a..?

A

Activation tree.

38
Q

What does the following declare?
int * f[ ] ()

A

An array of functions returning pointers to integers.

39
Q

A reference can never be NULL.

A

True.

40
Q

What does the following declare?
int (*f())[ ]

A

int (*f())[ ] declares a function returning a pointer to an array of integers.