wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Programming Lab Quiz

Total questions: 25

Worksheet time: 22mins

Name
Class
Date
1.

What is the correct syntax to declare a variable in C?

a)

int x;

b)

integer x;

c)

var x;

d)

x int;

2.

What will be the output of the following code?

int x = 5;

printf("%d", x++);

a)

6

b)

5

c)

Error

d)

Undefined

3.

Which of the following is the correct way to call a function in C?

a)

call myFunction();

b)

myFunction();

c)

function myFunction();

d)

def myFunction();

4.

What is the size of int in C (on a 32-bit machine)?

a)

8 bytes

b)

4 bytes

c)

2 bytes

d)

1 bytes

5.

What is the output of the following code?

int a = 10;

printf("%d", ++a);

a)

10

b)

11

c)

12

d)

Error

6.

Which of the following is not a valid data type in C?

a)

float

b)

real

c)

int

d)

char

7.

Which operator is used for "address of" in C?

a)

*

b)

&

c)

%

d)

#

8.

What is the correct syntax for a function using call by reference?

a)

void fun(int x)

b)

void fun(int *x)

c)

void fun(ref int x)

d)

void fun(int &x)

9.

What will the following code print?

int a = 2;

int b = a++ + ++a;

printf("%d", b);

a)

5

b)

6

c)

7

d)

8

10.

What does the following code output?

int x = 10;

printf("%d", *&x);

a)

10

b)

Address of x

c)

Error

d)

Garbage value

11.

Which of the following is true about main() function in C?

a)

It is optional.

b)

Execution starts from main().

c)

It can be called from other functions only.

d)

It is a library function.

12.

What does the following code return?

int x = 10;

printf("%d", x == 10);

a)

10

b)

1

c)

0

d)

Error

13.

What will be the output?

int a = 5;

printf("%d", a += 2);

a)

5

b)

7

c)

2

d)

Error

14.

Which is used to comment a single line in C?

a)

/* comment */

b)

// comment

c)

<!-- comment -->

d)

# comment

15.

Which is used to comment a multiple line in C?

a)

/* comment */

b)

// comment

c)

<!-- comment -->

d)

# comment

16.

What is the correct way to return a value from a function?

a)

return;

b)

return x;

c)

exit(x);

d)

return x, y;

17.

What is the output of the following code?

int x = 2;

switch (x) {

case 1:

printf("One ");

case 2:

printf("Two ");

case 3:

printf("Three ");

default:

printf("Default");

}

a)

Two

b)

Two Three Default

c)

One Two Three Default

d)

Error

18.

What will be the output of the following code?

int a = 5;

switch (a % 2) {

case 0:

printf("Even");

break;

case 1:

printf("Odd");

break;

default:

printf("Default");

}

a)

Even

b)

Odd

c)

Default

d)

Error

19.

What will be the output of the following code?

char grade = 'B';

switch (grade) {

case 'A':

printf("Excellent");

break;

case 'B':

printf("Good");

break;

case 'C':

printf("Average");

break;

default:

printf("Poor");

}

a)

Excellent

b)

Good

c)

Average

d)

Poor

20.

Which format specifier is used for float in printf()?

a)

%c

b)

%d

c)

%f

d)

%s

21.

Which of these will correctly swap two variables using call by reference?

void swap(int a, int b) {

int temp = *a;

a = b;

*b = temp;

}

a)

Correct

b)

Incorrect

c)

Will give error

d)

Will not swap

22.

What will be the output?

#include <stdio.h>

int main() {

int a = 5, b = 10;

int c = a++ + ++b;

printf("%d %d %d", a, b, c);

return 0;

}

a)

5 10 15

b)

6 11 16

c)

6 11 15

d)

5 11 15

23.

Output of this recursive function?

#include <stdio.h>

void print(int n) {

if(n > 0) {

print(n - 1);

printf("%d ", n);

}

}

int main() {

print(3);

return 0;

}

a)

3 2 1

b)

1 2 3

c)

2 3 1

d)

1 3 2

24.

What is the output of this pointer manipulation?

#include <stdio.h>

int main() {

int a = 10, b = 20;

int p = &a, q = &b;

p = q;

printf("%d %d", a, b);

return 0;

}

a)

10 10

b)

20 20

c)

20 10

d)

erroe

25.

What will this print?

char ch = 'A';

printf("%d", ch);

a)

A

b)

65

c)

'A'

d)

Error