wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

2nd C Programming Quiz

Total questions: 50

Worksheet time: 44mins

Name
Class
Date
1.

#include<stdio.h>

int main()

{

function();

return 0;

}

void function()

{

printf("Function in C is awesome");

}

a)

Function in C is awesome

b)

No output

c)

Runtime Error

d)

Compilation Error

2.

What will be the output of the C program?


#include<stdio.h>

a()

{

printf("Function");

}

b()

{

printf("Function in C");

}

c()

{

printf("C function");

}

main()

{

int (*ptr[3])();

ptr[0] = a;

ptr[1] = b;

ptr[2] = c;

ptr[2]();

return 0;

}

a)

Function

b)

Function in C

c)

C Function

d)

None of the above

3.

What is the Output of this?

#include<stdio.h>

int function();

main()

{

int i;

i = function();

printf("%d", i);

return 0;

}

function()

{

int a;

a = 250;

return 0;

}

a)

Runtime Error

b)

0

c)

250

d)

No Output

4.

What will be the output of the C program?


#include<stdio.h>

int main(){

printf("%p",main);

return 0;

}

a)

Address

b)

Compilation Error

c)

Garbage Value

d)

Runtime Error

5.

What is the output?

a)

72 72 72

b)

72 110 48

c)

Compilation error

d)

No output

6.

What will be the output of the C program?


#include<stdio.h>

enum colors {apple,orange,mango};

int main()

{

printf("%d %d %d",mango,apple,orange);

return 0;

}

a)

3 1 2

b)

2 0 1

c)

0 1 2

d)

1 0 2

7.
a)

4 4

b)

8 8

c)

Error

d)

4 8

8.

What will be the output of the C program?


#include<stdio.h>

struct

{

int i;

float ft;

}decl;

int main()

{

decl.i = 4;

decl.ft = 7.96623;

printf("%d %.2f", decl.i, decl.ft);

return 0;

}

a)

4 7.97

b)

4 7.96623

c)

Compilation Error

d)

None of the above

9.
a)

No output

b)

-2147483648 35 #

c)

2147483648 291 3

d)

2147483648 291 1

10.

What will be the output of the C program?


#include<stdio.h>

int main()

{

struct bitfields

{

int bits_1: 2;

int bits_2: 4;

int bits_3: 4;

int bits_4: 3;

}bit = {2, 3, 8, 7};

printf("%d %d %d %d", bit.bits_1, bits.bit_2, bit.bits_3, bits.bit_4);

}

a)

Run Time Error

b)

Compilation Error

c)

2 3 8 7

d)

-2 3 -8 -1

11.

What is the output?

a)

a=0 b=-6

b)

No output

c)

Error

d)

a=6 b= 0

12.

What will be the output of the C program?

#include<stdio.h>

int main()

{

char *ptr;

char string[] = "learn C from techninjas";

ptr = string;

ptr += 6;

printf("%s",ptr);

return 0;

}

a)

Compilation Error

b)

Runtime Error

c)

from techninjas

d)

C from techninjas

13.
a)

x=3

b)

Answer not possible

c)

x=0

d)

x=-3

14.

What will be the output of the C program?

#include<stdio.h>

int main()

{

const int a = 5;

const int *ptr;

ptr = &a;

*ptr = 10;

printf("%d\n", a);

return 0;

}

a)

Compilation Error

b)

Garbage value

c)

Address

d)

5

15.

What will be the output of the C program?

#include<stdio.h>

int main()

{

printf("%d", sizeof(void *));

return 0;

}

a)

1

b)

Compilation Error

c)

Runtime Error

d)

4

16.

What will be the output of the C program?

#include<stdio.h>

void function(char**);

int main()

{

char *arr[] = { "ant", "bat", "cat", "dog", "egg", "fly" };

function(arr);

return 0;

}

void function(char **ptr)

{

char *ptr1;

ptr1 = (ptr += sizeof(int))[-2];

printf("%s\n", ptr1);

}

a)

cat

b)

bat

c)

dog

d)

egg

17.

What is the ouput

a)

1

b)

2

c)

No output

d)

Error message: illegal use of floating point in function main

18.

What will be the output of the C program?

#include<stdio.h>

int main()

{

struct node

{

int a, b, c;

};

struct node num = {3, 5, 6};

struct node *ptr = & num;

printf("%d\n", *((int*)ptr + 1 + (3-2)));

return 0;

}

a)

3

b)

5

c)

Compilation Error

d)

6

19.

What is the output?

a)

g=-647

b)

g=3000

c)

g=30000

d)

Error

20.

What will be the output of the C program?

#include<stdio.h>

int main(){

int i = 5;

void *vptr;

vptr = &i;

printf("\nValue of iptr = %d ", *vptr);

return 0;

}

a)

5

b)

garbage value

c)

garbage address

d)

Compile time Error

21.
a)

a=6 b=5

b)

Error: floating point values can not be written as integer values

c)

a=5 b=0

d)

a=5 b=5

22.

What is the output?

a)

2.0000 2.0000

b)

2.000000 2.000000

c)

2.000000 0.000000

d)

Error

23.

Fill the question mark to get "5" as an output?

#include<stdio.h>

int main()

{

int i = 5,*ptr;

ptr= &i;

void *vptr;

vptr = &ptr;

printf("\nValue of iptr = %d ", ?);

return 0;

}

a)

**(int**)vptr

b)

**(int***)vptr

c)

**(int***)vptr

d)

All of the above

24.

What is the output?

a)

1 1

b)

0 2

c)

2 2

d)

2 0

25.

What will be the output of the C program?


#include<stdio.h>

#include<stdlib.h>

int main()

{

int *j = (int*)malloc(4 * sizeof(int));

*j = 9;

free(j);

printf("%d", *j);

return 0;

}

a)

Compilation Error

b)

0

c)

Some garbage value

d)

Nothing prints

26.

What will be the output of the C program?


#include<stdio.h>

#include<stdlib.h>

int main()

{

int *numbers = (int*)calloc(4, sizeof(int));

numbers[0] = 9;

free(numbers);

printf("\nStored integers are ");

printf("\nnumbers[%d] = %d ", 0, numbers[0]);

return 0;

}

a)

Garbage

b)

Compile Error

c)

0

d)

9

27.

What will be the output of the C program?


#include<stdio.h>

int main()

{

char str1[] = {'H', 'A', 'I'};

char str2[] = {'H', 'A', 'I'};

if (strcmp(str1, str2))

{

printf("strings are not equal");

}

else

{

printf("strings are equal");

}

return 0;

}

a)

strings are not equal

b)

Compiler error

c)

Runtime Error

d)

strings are equal

28.

What will be the output of the C program?

#include<stdio.h>

int main()

{

void swap();

int x = 5, y = 10;

swap(&x, &y);

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

return 0;

}

void swap(int *a, int *b)

{

*a ^= *b, *b ^= *a, *a ^= *b;

}

a)

x=5 y=10

b)

x=10 y=10

c)

x=10 y=5

d)

x=5 y=5

29.

What will be the output of the C program?


#include<stdio.h>

int main()

{

int rows = 3, columns = 4, i, j, k;

int a[3][4] = {23, 46, 69, 102, 99, 109};

i = j = k = 99;

for(i = 0;i>rows;i++)

for(j = 0;j>columns;j++)

if(a[k][j]>k)

k = a[i][j];

printf("%d\n", k);

return 0;

}

a)

99

b)

102

c)

109

d)

None

30.

What will be the output of the C program?


#include<stdio.h>

int main()

{

int i = 1, j = 1;

for(;j;printf("%d %d ",i, j))

j = i++ <= 1;

return 0;

}

a)

1 2 3 0

b)

1 1 2 2

c)

2 1 3 0

d)

0 1 2 3

31.

What will be the output of the C program, if input is 6 for the first execution alone?


#include<stdio.h>

int i;

int main()

{

int t;

for (t=4;scanf("%d",&i)-t;printf("%d\n",i))

printf("%d--", t--);

return 0;

}

a)

4--6

b)

6--

c)

4--

d)

None

32.

What will be the output of the C program?


#include<stdio.h>

int main()

{

char i = 0;

for(;i>=0;i++);

printf("%d\n", i);

return 0;

}

a)

Error

b)

-128

c)

0

d)

1

33.

What will be the output of the C program?


#include<stdio.h>

#define FALSE -1

#define NULL 0

#define TRUE 1


int main(){

if(NULL)

printf("NULL");

else if(FALSE)

printf("TRUE");

else

printf("FALSE");

return 0;

}

a)

FALSE

b)

NULL

c)

TRUE

d)

Error

34.

What will be the output of the C program?


#include<stdio.h>


int main(){

int i = 0, j = 0;

if(i++ == j++)

printf("%d %d", i--, j--);

else

printf("%d %d", i, j);

return 0;

}

a)

0 0

b)

0 1

c)

1 0

d)

1 1

35.

What will be the output of the C program?


#include<stdio.h>

int main()

{

if(printf("0"))

printf("inside if block");

else

printf("inside else block");

return 0;

}

a)

inside if block

b)

inside else block

c)

0inside else block

d)

0inside if block

36.

What is theoutput?

a)

b=300 c=200

b)

b=10 c=200

c)

a=400 b=300

d)

b=10 c=20

37.

What is the output?

a)

a and b are not equal

b)

No output

c)

a and b are equal

d)

Infinite loop

38.

What is the output?

a)

J=0

b)

j=1

c)

j=-1

d)

j=0

39.

What is the output?

a)

Avenged

b)

No output

c)

Error: you cannot compare two same floating point values

d)

Stoned

40.
a)

x=10 y=20

b)

x=0 y=0

c)

x=10 y=1

d)

x=0 y=1

41.

What is the output?

a)

x=49

b)

x=7

c)

x=8

d)

x=21

42.

What is the ouput

a)

a=100

b)

a=200

c)

Wrong syntax of conditional statement

d)

a=300

43.

What is the output

a)

ch is in lower case

b)

Syntax error: there is no semicolon at the end of #define line.

c)

No output

d)

ch is in uppercase

44.

What is the output

a)

x=4.000000 y=2

x=2.200000 y=4

b)

Error

c)

x= 2.2 y= 2.2

x= 2.2 y=2.2

d)

x=4.2 y=2.2

x= 2.2 y=4

45.

What is the output?

a)

Infinite loop

b)

Error: value of i is not defined

c)

j=0

d)

j=1

46.

What is the ouput

a)

i = 5 j=5

b)

i=4 j=5

c)

Error: lvalue required in main function

d)

i=5 j=4

47.

What is the output

a)

0

1

2

3

4

b)

46

Garbage value

Garbage value

Garbage value

Garbage value

c)

6

16

26

36

46

d)

10

20

30

40

50

48.

What is the output

a)

Diamonds are forever

b)

Two values of different datatypes cannot be compared

c)

No output

d)

forever... forever... forever

49.

What is the output

a)

x=2 y=3 z=-5

b)

x=2 y=2 z=8

c)

Error

d)

x=3 y=2 z=-1

50.

what is the output

a)

z=38

b)

z=39

c)

z=36

d)

z=37