Quiz 2 Flashcards

1
Q

Stack-allocated variables continue to exist even after the function where they were created returns

True
False
A

False

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

Does a variable allocated using malloc() need to be deallocated by the programmer?

No, the OS takes care of deallocating them

No, the compiler takes care of deallocating them

Yes, using the unmalloc() function call

Yes, using the free() function call

A

Yes, using the free() function call

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

In C, the programmer is responsible for deciding whether a variable is stored in memory or a CPU register

True

False
A

True

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

C is a compiled language

True
False
A

True

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

The snippet below always prints “True”:

if ( 1 )
printf(“True”);
else
printf(“False”);

True
False
A

True

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

The snippet #define min(a, b) (a < b ? A : b) defines a preprocessor _____ . It is similar to a function, but may be faster than a function call.

A

The snippet #define min(a, b) (a < b ? A : b) defines a preprocessor macro. It is similar to a function, but may be faster than a function call.

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

Select all the memory regions where pointers can be allocated from a C program

Storage

Heap

Swap

Stack

A

Heap

Stack

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

What is the result of the command below?

gcc -o myfile myfile.c

The compiler returns an error due to incorrect command line parameters

“myfile.c” gets overwritten by an executable program called “myfile”

“myfile.c” gets compiled to an executable file called “myfile.out”

“myfile.c” gets compiled to an executable program called “myfile”

A

“myfile.c” gets compiled to an executable program called “myfile”

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

The following command is the correct one to compile “example.c”:

gcc -o example.c example

True
False
A

False

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

What happens if I run “int* ptr = 0; *ptr = 42;” ?

The value pointed at by ptr is set to 0

The value pointed at by ptr is set to 42

Nothing; the code does not compile

Segmentation fault (the program crashes)

A

Segmentation fault (the program crashes)

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

A C header file typically has extension . ______(50 %) . In order to use header files in source code, they must imported using the # ______(50 %) preprocessor directive.

A

A C header file typically has extension . ___h___(50 %) . In order to use header files in source code, they must imported using the # ___include___(50 %) preprocessor directive.

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

What is the correct way to modify the location stored by the “myptr” pointer?

*myptr = 42;

&myptr = 42;

myptr = 42;

%myptr = 42;

A

myptr = 42;

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

What is a concrete, unambiguous difference between C and Python?

C is compiled, Python is interpreted

C can be used to read/write files, Python cannot

C is fast, Python is slow

Python allows to divide a program in multiple source files, C does not

A

C is compiled, Python is interpreted

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

Memory for variables stored on the heap must be manually allocated using the ______ function.

A

Memory for variables stored on the heap must be manually allocated using the ___malloc___ function.

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

In C, what does the following snipped do?

register int myvar = 42;

Tell the compiler that myvar should be stored in a register

Tell the preprocessor to replace every instance of the string “myvar” with the string “42”

Write the value 42 into all CPU registers

Tell the compiler to move myvar out of a register

A

Tell the compiler that myvar should be stored in a register

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