wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

C Programming Multiple Choice Questions

Total questions: 40

Worksheet time: 40mins

Name
Class
Date
1.

Which operator is used to access the address of a variable?

a)

*

b)

&

c)

#

d)

@

2.

What is the output?

int a = 10, b = 5, c;

c = a > b ? a : b;

printf("%d", c);

a)

10

b)

5

c)

0

d)

1

3.

What is the output of the following code? #include <stdio.h>

int main() {

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

int *p = a;

printf("%d", *(p + 2));

return 0;

}

a)

1

b)

2

c)

3

d)

Garbage Value

4.

Which of the following is a valid main function declaration?

a)

void main()

b)

int main()

c)

main()

d)

All of the above

5.

What is the output?

#include <stdio.h>

void main() {

static int i;

printf("%d", i);

}

a)

Garbage value

b)

0

c)

1

d)

Error

6.

Which function is used to read a string from the standard input?

a)

gets()

b)

scanf()

c)

getchar()

d)

Both a and b

7.

What is the role of the stdlib.h header file?

a)

Standard Input/Output

b)

String operations

c)

Memory allocation functions like malloc()

d)

Mathematical functions

8.

What is the output of printf("%d", 5 + 3 * 2);?

a)

16

b)

11

c)

10

d)

13

9.

Identify the problem with this code related to memory management.

a)

Memory leak

b)

Dangling pointer

c)

Nothing, it's correct.

d)

malloc is used incorrectly.

10.

Which of the following is a logical AND operator?

a)

&

b)

&&

c)

|

d)

||

11.

What is the output? int x = 5;

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

a)

5 6 6

b)

7 7 5

c)

5 6 5

d)

The output is compiler-dependent.

12.

What is the keyword used to define a constant value in C?

a)

constant

b)

#define

c)

const

d)

#Define

13.

What is the output if the user enters "5"?

int num;

if (scanf("%d", &num))

printf("Valid");

else

printf("Invalid");

a)

Valid

b)

Invalid

c)

Error

d)

Undefined

14.

What is the value of a local variable that is not initialized?

a)

0

b)

1

c)

A garbage value

d)

NULL

15.

What is the output of printf("%d", 10 / 3);?

a)

3.33

b)

3

c)

4

d)

3.0

16.

What is the output?

char str[] = "Hello";

printf("%d", sizeof(str));

a)

5

b)

6

c)

7

d)

Garbage value

17.

What is the size of the int data type in a typical 32-bit C compiler?

a)

1 byte

b)

2 bytes

c)

4 bytes

d)

8 bytes

18.

What does the strcmp(str1, str2) function return if str1 and str2 are equal?

a)

1

b)

0

c)

-1

d)

The length of the string

19.

What is the output?

int i = 2;

int j = i++ + ++i;

printf("%d", j);

a)

4

b)

5

c)

6

d)

Undefined / Compiler-dependent

20.

Which loop is guaranteed to execute at least once?

a)

for loop

b)

while loop

c)

do-while loop

d)

None of the above

21.

What is the value of x after the execution?

int x = 10;

int *ptr = &x;

*ptr = 20;

a)

10

b)

20

c)

Address of x

d)

Garbage value

22.

What is the correct extension for a C source file?

a)

.c

b)

.cpp

c)

.java

d)

.py

23.

What does the continue statement is used to:

a)

Exit from the main function

b)

Exit from the current loop iteration

c)

Jump to a label

d)

Restart the program

24.

What is the output of printf("%c", 'A' + 1);?

a)

A

b)

B

c)

66

d)

Error

25.

25. What Does this code demonstrate

#include <stdio.h>

int main() {

int x = 10;

{

int x = 20;

printf("%d ", x);

}

printf("%d", x);

return 0;

}

a)

Global variable

b)

Scope of a variable

c)

Lifetime of a variable

d)

Both b and c

26.

Which of the following correctly declares a pointer to a function that takes an integer and returns a float?

a)

float *f(int);

b)

float (*f)(int);

c)

float (*f)(int*);

d)

float f(int *);

27.

What is the output?

#include <stdio.h>

int main() {

int i = 0;

for(; i; i--)

printf("Hello ");

return 0;

}

a)

Prints "Hello" infinitely

b)

Prints "Hello" once

c)

Does not print anything

d)

Error

28.

A function in C can return:

a)

Only one value

b)

Multiple values

c)

No value

d)

Both a and c

29.

What will the following code print?

#include <stdio.h>

void fun(int *x) {

x = x + 10;

}

int main() {

int a = 5;

fun(&a);

printf("%d", a);

return 0;

}

a)

5

b)

10

c)

15

d)

Error

30.

Which header file is needed to use the printf() and scanf() functions?

a)

<conio.h>

b)

<stdlib.h>

c)

<stdio.h>

d)

<math.h>

31.

What does the break statement do inside a loop?

a)

Skips the current iteration

b)

Exits the loop immediately

c)

Restarts the loop

d)

Pauses the program

32.

What is a structure in C?

a)

A collection of same data types

b)

A collection of different data types

c)

A special type of function

d)

A type of pointer

33.

C is a _____ language.

a)

High-Level

b)

Low-Level

c)

Assembly

d)

Machine

34.

The printf function is used for:

a)

Taking input

b)

Displaying output

c)

Allocating memory

d)

File operations

35.

Which of the following is the correct way to declare a string?

a)

char str[20] = {'C', 'L', 'A', 'N', 'G'};

b)

char str[] = "CLANG";

c)

char *str = "CLANG";

d)

All of the above

36.

An array index in C always starts from:

a)

0

b)

1

c)

-1

d)

Can be defined by the user

37.

What does the following code do? int *p; int a = 10; p = &a;

a)

Declares p as an integer

b)

Makes p point to the address of a

c)

Makes p hold the value of a

d)

Declares a new variable

38.

The switch statement is used with:

a)

Integer expressions

b)

Character expressions

c)

Floating-point expressions

d)

Both a and b

39.

In a 1D array int arr[5];, what does arr represent?

a)

The first element

b)

The base address of the array

c)

The last element

d)

The size of the array

40.

Which format specifier is used for a float value?

a)

%d

b)

%f

c)

%c

d)

%lf