WorksheetsCMDP2063 Unix and C Programming
Total questions: 15
Worksheet time: 19mins
What is the correct syntax for a block comment in C?
// Being weak is nothing to be ashamed of. Staying weak is.
<!-- Being weak is nothing to be ashamed of. Staying weak is. -->
/* Being weak is nothing to be ashamed of. Staying weak is. */
#Being weak is nothing to be ashamed of. Staying weak is.
What happens if you try to use a // comment in C89?
The code will compile successfully.
It will cause a syntax error.
The comment will be ignored, and the code will run normally.
The // will be treated like a block comment.
What will be the output of the following C program?
0 1 2 3 4
0 1 2 3
0 1 2
No output
What happens in this program when the square() function is called?
16 16
4 4
Compile Error
16 4
Which of the following format specifiers is used to print a floating-point value using printf()?
%f
%d
%c
%s
What is the output of the following program in the image when using printf()?
I have been learning %c for %d %s.
I have been learning c for %d days.
I have been learning for 42 days.
I have been learning C for 42 days.
What is the benefit of using forward declarations in C?
To reduce the size of the executable file
To allow the use of functions before they are defined in the source code
To enhance the readability of the code
To automatically generate documentation
What does the -Wall option do when compiling with gcc?
It suppresses all warnings.
It generates a log file of all warnings.
It enables all warnings to help identify potential issues in the code.
It compiles the program in C89 mode.
What command is used to run a compiled C program named school?
If you have a calc.c file, what is the correct way to include its corresponding header file?
Answer: (a)
Which of the following correctly defines a macro named MAX that represents the maximum value of two numbers?
#define MAX(x, y) x > y ? x : y
#define MAX(x, y) (x > y) ? x : y;
#define MAX(x, y) (x > y) ? x : y
#define MAX(x, y) x > y ? (x) : (y)
What will the following code output?
Midterm
Midterm Exam is Next Week!
REMINDER
Undefined
What will happen if the following macro is defined?
It will cause a compile error.
The result will be 14.
The result will be 24.
The result will be 20.
In a Linux environment, which shell is commonly used?
PowerShell
Bash (Bourne Again Shell)
Zsh (Z Shell)
Command Prompt
What does the following code do?
It changes the value of a to 10.
It causes a segmentation fault.
It changes the value of p to 10.
It creates a new variable a with a value of 10.
