Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

C Code Master

Total questions: 20

Worksheet time: 10mins

Name
Class
Date
1.

What will the result of num1 variable after execution of the following statements?

int j = 1, num1 = 4;

while (++j <= 10)

{

num1++;

}

a)

11

b)

12

c)

13

d)

14

2.

What is the output of the following

printf("%d",34+24/12%3*5/2-4);

a)

35

b)

34

c)

32

d)

37

3.

c = (n) ? a : b; can be rewritten as

exp1 ? exp2 : exp3;

a)

if(n){c = a;}else{c = b;}

b)

if(!n){c = a;}else{c = b;}

c)

if(n){c = b;}else{c = a;}

d)

None of the above

4.

What is the output of the following code.

void main()

{

int i = 0;

   

   if (i == 0)

    {

       printf("Hello");

     break;

    }

}

a)

Hello is printed infinite times

b)

Hello

c)

compile time error

d)

varies

5.

Point out the wrong statement about malloc.

a)

Allocated memory has undefined value

b)

Pointer is NULL if memory is not allcoated

c)

It returns pointer to the allocated space

d)

It doesn't lead to memory leak if memory is not de allocated

6.

What is the result after execution of the following code if a is 10, b is 5, and c is 10?

if ((a > b) && (a <= c))

a = a + 1;

else

c = c+1;

a)

a = 10, c = 10

b)

a = 11, c = 10

c)

a = 11, c = 11

d)

a = 10, c = 11

7.

What is the output of this code?

char ch;

ch=A;

printf(“%c”,ch);       

a)

Compile time error

b)

A

c)

65

d)

garbage value

8.

Which of the following is an invalid assignment operator?

a)

A%=10; 

b)

  A/=10; 

c)

A|=10   

d)

none

9.

What is the output of this C code?

int main()

{

int a = 2;

int b = 0;

int y = (b == 0) ? a :(a > b) ? (b = 1): a;

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

}

a)

1

b)

2

c)

Compile time error

d)

Undifined

10.

Comment on the output of this C code?

int main() 

{ 

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

   int i;       

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

   if ((char)a[i] == '5')        

        printf("%d\n", a[i]);   

         else        

        printf("FAIL\n");  

  }

a)

Program will compile and print the output 5

b)

Error will generate

c)

print the ASCII value of 5

d)

print FAIL for 5 times

11.

What following operator is called

?:

a)

Scope resolution

operation

b)

condition

operation

c)

ternary operation

d)

loop operation

12.

What is the output of the below program?

int main()

{

for(; ;)

for(; ;)

printf("Hello..");

return 0;

}

a)

Hello..

b)

Runtime Error

c)

Hello.. is printed two time

d)

Hello.. is printed infinite times

13.

How would you round off a value from 1.66 to 2.0?

a)

ceil(1.66)

b)

floor(1.66)

c)

roundto(1.66)

d)

roundup(1.66)

14.

What is the output of the program given below ?

a)

1, 2, 3

b)

2, 1, 0

c)

1, 0, 2

d)

0, 2, 1

15.

What will be the output of the following C code?

a)

8 3

b)

3 8

c)

5 3

d)

8 5

16.

What is the use of rewind() function in C?

a)

gives current position in the file

b)

set the position to the beginning point

c)

set the position to desire point

d)

None of these

17.

What is the result on the console screen?

a)

1 1

b)

2 2

c)

compile time error

d)

runtime error

18.

What will be the final value of the c in the following c statement.

int c=2;

c<<=1;

printf("%d",c);

a)

1

b)

3

c)

4

d)

0

19.

What will be the output of the following C code?

#include <stdio.h>

int main()

{

while ()

printf("In while loop ");

printf("After loop\n");

}

a)

In while loop after loop

b)

After loop

c)

Compile time error

d)

Infinite loop

20.

What will be the output of following code.

#include "stdio.h"

int main()

{

int x = 50;

int y = 60;

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

printf("#%d %d", ++x, --y);

return 0;

}

a)

50 59#51 59

b)

50 60#51 59

c)

51 59#52 58

d)

50 60#52 58