Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

CMDP2063 Unix and C Programming

Total questions: 15

Worksheet time: 19mins

Name
Class
Date
1.

What is the correct syntax for a block comment in C?

a)

// Being weak is nothing to be ashamed of. Staying weak is.

b)

<!-- Being weak is nothing to be ashamed of. Staying weak is. -->

c)

/* Being weak is nothing to be ashamed of. Staying weak is. */

d)

#Being weak is nothing to be ashamed of. Staying weak is.

2.

What happens if you try to use a // comment in C89?

a)

The code will compile successfully.

b)

It will cause a syntax error.

c)

The comment will be ignored, and the code will run normally.

d)

The // will be treated like a block comment.

3.

What will be the output of the following C program?

a)

0 1 2 3 40\ 1\ 2\ 3\ 4

b)

0 1 2 30\ 1\ 2\ 3

c)

0 1 20\ 1\ 2

d)

No output

4.

What happens in this program when the square() function is called?

a)

16   1616\ \ \ 16

b)

4   44\ \ \ 4

c)

Compile Error

d)

16    416\ \ \ \ 4

5.

Which of the following format specifiers is used to print a floating-point value using printf()?

a)

%f

b)

%d

c)

%c

d)

%s

6.

What is the output of the following program in the image when using printf()?

a)

I have been learning %c for %d %s.

b)

I have been learning c for %d days.

c)

I have been learning for 42 days.

d)

I have been learning C for 42 days.

7.

What is the benefit of using forward declarations in C?

a)

To reduce the size of the executable file

b)

To allow the use of functions before they are defined in the source code

c)

To enhance the readability of the code

d)

To automatically generate documentation

8.

What does the -Wall option do when compiling with gcc?

a)

It suppresses all warnings.

b)

It generates a log file of all warnings.

c)

It enables all warnings to help identify potential issues in the code.

d)

It compiles the program in C89 mode.

9.

What command is used to run a compiled C program named school?

4 lines
10.

If you have a calc.c file, what is the correct way to include its corresponding header file?

Answer: ​​​ (a)   ​ ​

Choose from the below words
#include <calc.h>
#include calc.h
#include "calc.c"
#include "calc.h"
11.

Which of the following correctly defines a macro named MAX that represents the maximum value of two numbers?

a)

#define MAX(x, y) x > y ? x : y

b)

#define MAX(x, y) (x > y) ? x : y;

c)

#define MAX(x, y) (x > y) ? x : y

d)

#define MAX(x, y) x > y ? (x) : (y)

12.

What will the following code output?

a)

Midterm

b)

Midterm Exam is Next Week!

c)

REMINDER

d)

Undefined

13.

What will happen if the following macro is defined?

a)

It will cause a compile error.

b)

The result will be 14.

c)

The result will be 24.

d)

The result will be 20.

14.

In a Linux environment, which shell is commonly used?

a)

PowerShell

b)

Bash (Bourne Again Shell)

c)

Zsh (Z Shell)

d)

Command Prompt

15.

What does the following code do?

a)

It changes the value of a to 10.

b)

It causes a segmentation fault.

c)

It changes the value of p to 10.

d)

It creates a new variable a with a value of 10.