wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

C programming quiz 1

Total questions: 20

Worksheet time: 10mins

Name
Class
Date
1.

Which of the following is NOT a valid C data type?

a)

int

b)

float

c)

real

d)

char

2.

What is the size of int in most 32-bit compilers?

a)

1 byte

b)

2 bytes

c)

4 bytes

d)

8 bytes

3.

Which operator has the highest precedence?

a)

+

b)

*

c)

=

d)

&&

4.

What is the output of 5 / 2 in C?

a)

2.5

b)

2

c)

3

d)

2.0

5.

Which operator is used to access the value stored at an address?

a)

&

b)

%

c)

->

d)

*

6.

Which keyword is used for a multiway branching statement?

a)

if

b)

for

c)

switch

d)

goto

7.

What will be the output of this code?

int a = 10;

if(a > 5)

printf("Yes");

else

printf("No");

a)

Yes

b)

No

c)

Error

d)

Nothing

8.

How many times will this run?

for(int i=0; i<5; i++)

a)

4

b)

5

c)

6

d)

Infinite

9.

Which loop must execute at least once?

a)

for

b)

while

c)

do-while

d)

None

10.

Arrays in C are __________

a)

Dynamically sized

b)

Always 1-indexed

c)

Collection of different data types

d)

Collection of similar data types

11.

What is the index of the first element in an array?

a)

0

b)

1

c)

depends on compiler

d)

none

12.

What will this print?

int arr[5] = {1,2,3,4,5};

printf("%d", arr[2]);

a)

1

b)

2

c)

3

d)

4

13.

Which operator checks equality?

a)

=

b)

==

c)

!=

d)

:=

14.

What will be the output?

int a = 3;

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

a)

3

b)

4

c)

Compile error

d)

0

15.

Which operator is used for logical AND?

a)

&

b)

&&

c)

|

d)

||

16.

Which is a valid array declaration?

a)

int arr();

b)

arr[10] int;

c)

array int[10];

d)

int arr[10];

17.

What is the output?

int x = 10, y = 20;

printf("%d", x > y);

a)

0

b)

1

c)

10

d)

20

18.

Which of the following is NOT a loop in C?

a)

for

b)

iterate

c)

while

d)

do-while

19.

What is the datatype of 'A' in C?

a)

string

b)

int

c)

char

d)

float

20.

What is the output of the following code?

#include <stdio.h>

int main() {

int arr[5] = {2, 4, 6, 8, 10};

int i, sum = 0;

for(i = 0; i < 5; i++) {

arr[i] = arr[(i + 2) % 5] - arr[i];

sum += arr[i];

}

printf("%d", sum);

return 0;

}

a)

4

b)

6

c)

-4

d)

-6