Quiz 2 Flashcards
Stack-allocated variables continue to exist even after the function where they were created returns
True False
False
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
Yes, using the free() function call
In C, the programmer is responsible for deciding whether a variable is stored in memory or a CPU register
True False
True
C is a compiled language
True False
True
The snippet below always prints “True”:
if ( 1 )
printf(“True”);
else
printf(“False”);
True False
True
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.
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.
Select all the memory regions where pointers can be allocated from a C program
Storage
Heap
Swap
Stack
Heap
Stack
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”
“myfile.c” gets compiled to an executable program called “myfile”
The following command is the correct one to compile “example.c”:
gcc -o example.c example
True False
False
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)
Segmentation fault (the program crashes)
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 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.
What is the correct way to modify the location stored by the “myptr” pointer?
*myptr = 42;
&myptr = 42;
myptr = 42;
%myptr = 42;
myptr = 42;
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
C is compiled, Python is interpreted
Memory for variables stored on the heap must be manually allocated using the ______ function.
Memory for variables stored on the heap must be manually allocated using the ___malloc___ function.
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
Tell the compiler that myvar should be stored in a register