wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

C Programming Quiz

Total questions: 50

Worksheet time: 9mins

Name
Class
Date
1.

Which of the following statements about pointers is correct?

a)

A pointer stores the value of a variable.

b)

A pointer stores the memory address of a variable.

c)

A pointer stores the size of a variable.

d)

A pointer is used to add two values.

2.

Which of the following is true about sizeof() operator?

a)

It can be used on any data type.

b)

It returns the size in bits.

c)

It can only be used on variables.

d)

It returns the size in bytes.

3.

What will printf("%d", 5 + 3); output?

a)

53

b)

8

c)

35

d)

5 + 3

4.

What is the format specifier for printing an integer in C?

a)

%c

b)

%s

c)

%d

d)

%f

5.

Which of the following is used to clear memory allocated by malloc()?

a)

clear()

b)

free()

c)

delete()

d)

reset()

6.

What is the output of the following code? int a = 5, b = 3; printf("%d", a % b);

a)

1

b)

2

c)

3

d)

5

7.

Which function is used to dynamically allocate memory in C?

a)

malloc()

b)

free()

c)

sizeof()

d)

realloc()

8.

Consider the following declaration of a 'two-dimensional array in C: char a[100][100]; Assuming that the main memory is byte-addressable and that the array is stored starting from memory address 0, the address of a[40][50] is

a)

4040

b)

4050

c)

5040

d)

5050

9.

What will be the output of the following C code?

a)

Error because function name cannot be preceded by const

b)

Sanfoundry.com

c)

Sanfoundry.com is printed infinite times

d)

Blank screen, no output

10.

What will be the final value of x in the following C code?

a)

3.75

b)

Depends on compiler

c)

24

d)

3

11.

What will be the result of code?

a)

16

b)

8

c)

6

d)

4

12.

What is the return value of the function foo when it is called as foo(345, 10) ?

a)

345

b)

12

c)

5

d)

3

13.

What will be the output of C code?

a)

128

b)

-128

c)

Depends on the compiler

d)

None of the mentioned

14.

Which type of function does not return a value?

a)

int

b)

char

c)

void

d)

float

15.

What does the term "pointer to pointer" mean?

a)

It refers to a pointer that stores the address of another pointer.

b)

It is a pointer that stores an integer.

c)

It is a pointer that stores the size of a variable.

d)

It refers to a pointer that can point to multiple values.

16.

Which of the following statements is true for a pointer in C?

a)

A pointer holds the address of another variable.

b)

A pointer stores the value of another variable.

c)

A pointer stores the name of another variable.

d)

A pointer cannot point to another pointer.

17.

Which of the following correctly initializes an array in C?

a)

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

b)

int arr[3] = 1, 2, 3;

c)

int arr(3) = {1, 2, 3};

d)

int arr[] = 1, 2, 3;

18.

What is the output of the following code? int a = 1; int b = a << 2; printf("%d", b);

a)

1

b)

2

c)

4

d)

8

19.

What is the default return type of the main() function in C?

a)

int

b)

float

c)

void

d)

char

20.

What is the result of this C program?

a)

10

b)

20

c)

Random value

d)

Compilation error

21.

Tell me which one of the following is true.

a)

An array, each element of which is a pointer to a structure of type node

b)

A structure of 2 fields, each field being a pointer to an array of 10 elements

c)

A structure of 3 fields: an Integer, a float, and an array of 10 elements

d)

An array, each element of which is a structure of type node.

22.

Consider these two functions and two statements S1 and S2 about them.

S1: The transformation from work1 to work2 is valid, i.e., for any program state and input arguments, work2 will compute the same output and have the same effect on program state as work1

S2: All the transformations applied to work1 to get work2 will always improve the performance (i.e reduce CPU time) of work2 compared to work1

a)

S1 is false and S2 is false

b)

S1 is false and S2 is true

c)

S1 is true and S2 is false

d)

S1 is true and S2 is true

23.

Which of the following loops will not run infinitely?

a)

All will run infinitely

b)

None will run infinitely

c)

Only the for loop will not run infinitely

d)

Only the while loop will run infinitely

24.

What does the fragment of the C-program print?

a)

GATE2011

b)

E2011

c)

2011

d)

011

25.

What does the following C-statement declare? int ( * f) (int * ) ;

a)

A function that takes an integer pointer as argument and returns an integer

b)

A function that takes an integer as argument and returns an integer pointer

c)

A pointer to a function that takes an integer pointer as argument and returns an integer.

d)

A function that takes an integer pointer as argument and returns a function pointer

26.

What does the program print?

a)

8, 4, 0, 2, 14

b)

8, 4, 0, 2, 0

c)

2, 0, 4, 8, 14

d)

2, 0, 4, 8, 0

27.

What is #include ?

a)

Preprocessor directive

b)

Inclusion directive

c)

File inclusion directive

d)

None of the mentioned

28.

All keywords in C are in ____________

a)

LowerCase letters

b)

UpperCase letters

c)

CamelCase letters

d)

None of the mentioned

29.

What is the meaning of the following C statement? printf("%10s", state);

a)

10 spaces before the string state is printed

b)

Print empty spaces if the string state is less than 10 characters

c)

Print the last 10 characters of the string

d)

None of the mentioned

30.

What will happen if the following C code is executed?

a)

It will cause a compile-time error

b)

It will cause a run-time error

c)

It will run without any error and prints 3

d)

It will experience infinite looping

31.

What is the correct syntax for declaring a pointer to a function that returns an int and takes int as an argument?

a)

int (p)();

b)

int p(int);

c)

int (p)(int);

d)

int p(int);

32.

Which function in C is used to compare two strings?

a)

strcmp()

b)

strcat()

c)

strcpy()

d)

strlen()

33.

What is the output of this code?

a)

3

b)

5

c)

10

d)

15

34.

What is the size of an integer (int) in C on a 32bit system?

a)

2 bytes

b)

4 bytes

c)

1 byte

d)

8 bytes

35.

Which of the following functions in C is used to read formatted input?

a)

scanf()

b)

printf()

c)

gets()

d)

puts()

36.

Which of the following declaration is not supported by C language?

a)

String str;

b)

char *str;

c)

float str = 3e2;

d)

Both "String str;" and "float str = 3e2;"

37.

What is the output of this code?

a)

9

b)

10

c)

11

d)

Undefined behavior

38.

What is the result of this program as it is executed?

a)

15

b)

16

c)

17

d)

18

39.

What will printf("%d", 12 | 5); output?

a)

12

b)

5

c)

13

d)

17

40.

What will this code print?

a)

5

b)

10

c)

15

d)

Undefined behavior

41.

What will be the output of the C code?

a)

H

b)

e

c)

l

d)

o

42.

What is the result of sizeof(double) on most systems?

a)

2

b)

4

c)

8

d)

16

43.

What is the output of the following code? int a = 7; printf("%d", a >> 1);

a)

3

b)

7

c)

14

d)

1

44.

Which function is used to deallocate memory in C?

a)

malloc()

b)

free()

c)

calloc()

d)

sizeof()

45.

Which of the following is a correct declaration of a function pointer?

a)

int func(int);

b)

int (func)(int);

c)

int func(int );

d)

int func(int );

46.

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

a)

int x;

b)

int x =;

c)

int x:

d)

x = int;

47.

The C-preprocessors are specified with _________ symbol.

a)

#

b)

$

c)

" "

d)

&

48.

what is the value returned by f(1)?

a)

5

b)

6

c)

7

d)

8

49.

Which of the following is used to allocate a block of memory in C?

a)

malloc()

b)

calloc()

c)

realloc()

d)

all of the above

50.

Which header file is needed to use dynamic memory allocation functions?

a)

stdio.h

b)

stdlib.h

c)

malloc.h

d)

memory.h