wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

C programming

Total questions: 65

Worksheet time: 2hrs 10mins

Name
Class
Date
1.

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 = 10, c = 11

d)

a = 11, c = 11

2.

Which one of the following is a loop construct that will always be executed once?

a)

for

b)

while

c)

switch

d)

do while

3.

What will the result of 'num' variable after execution of the following statements?

int num = 58;

num % = 11;

a)

3

b)

5

c)

8

d)

11

4.

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

5.

What will be the output of the C code?

a)

Hello World! x;

b)

Hello World! followed by a junk value

c)

Compile time error

d)

Hello World!

6.

What will be the output of the following C code?

a)

2

b)

8

c)

9

d)

10

7.

What will be the output of the following C code?

a)

3 2 3

b)

2 2 3

c)

3 2 2

d)

2 3 3

8.

What will be the output of the following C code?

a)

Run time error

b)

7

c)

8

d)

Depends on compiler

9.

What will be the output of the following C code?

a)

True

b)

False

c)

True False

d)

No Output

10.

What will be the output of the following C code? (Assuming that we have entered the value 1 in the standard input)

a)

1

b)

2

c)

1 2

d)

Run Time Error

11.

What will be the output of the following C code?

a)

Hi is printed 9 times

b)

Hi is printed 8 times

c)

Hi is printed 7 times

d)

Hi is printed 6 times

12.

What will be the output of the following C code?

a)

H

b)

H is printed infinite times

c)

Compile time error

d)

Varies

13.

What will be the output of the following C code?

a)

hello 5

b)

Error

c)

Nothing

d)

Junk value

14.

What will be the output of the following C code?

a)

Undefined behavior

b)

Output will be 3

c)

Output will be 6

d)

Output will be 5

15.

What will be the output of the following C code

a)

6 -6 0 0

b)

6 -5 0 1

c)

-6 -6 0 1

d)

6 -6 0 1

16.

#include statement must be written __________

a)

Before main()

b)

Before any scanf() / printf()

c)

After main()

d)

It can be written anywhere

17.

What will be the output of the following C code?

#include <stdio.h>

void main()

{

int x = 5;

if (x < 1)

printf("hello");

if (x == 5)

printf("hi");

else

printf("no");

}

a)

hi

b)

hello

c)

no

d)

error

18.

What will be the output of the following C code?

#include <stdio.h>

int main()

{

int x = 0;

if (x == 1)

if (x == 0)

printf("inside if\n");

else

printf("inside else if\n");

else

printf("inside else\n");

}

a)

inside if

b)

inside else if

c)

inside else

d)

compile time error

19.

What will be the output of the following C code?

#include <stdio.h>

int main()

{

int x = 0;

if (x == 1)

if (x >= 0)

printf("true\n");

else

printf("false\n");

}

a)

Depends on the compiler

b)

No print statement

c)

True

d)

False

20.

The switch statement takes a given integer value then seeks a matching value among a number of _______ statements.

a)

break

b)

case

c)

switch

d)

goto

21.

How many loops are there in C

a)

1

b)

3

c)

2

d)

4

22.

Which of the following is an exit control statement

a)

for

b)

while

c)

do while

d)

continue

23.

The output of the following segment is

int k, n=20;

k=(n>5?(n<=10?100:200):500);

printf("%d",n);

a)

100

b)

200

c)

300

d)

20

24.

The value of i after the execution of the following segment is

i = 2;

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

a)

1

b)

2

c)

0

d)

11

25.

Which of the following is not a correct variable type?

a)

float

b)

real

c)

int

d)

double

26.

What will be the output of the following C code?

#include <stdio.h>

int main()

{

int a = 1, b = 1, c;

c = a++ + b;

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

}

a)

a=1, b=1

b)

a=2, b=1

c)

a=1, b=2

d)

a=2, b=2

27.

What will be the output of the following C code?

#include <stdio.h>

int main()

{

int i = 0;

int j = i++ + i;

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

}

a)

0

b)

1

c)

2

d)

compile time error

28.

What will be the output of the following C code?

#include <stdio.h>

int main()

{

int a = 1, b = 1;

switch (a)

{

case a*b:

printf("yes ");

case a-b:

printf("no\n");

break;

}

}

a)

yes

b)

no

c)

yes no

d)

compile time error

29.

Is it possible to run program without main() function?

a)

yes

b)

no

c)

may be

30.

How many main() function we can have in our project?

a)

1

b)

2

c)

no limit

d)

depends on the program

31.

int x = 10;


int main()

{

int x = 0;

printf("%d",x);

return 0;

}

a)

10

b)

0

c)

compile error

d)

undefined

32.

What should be the output:

int main()

{

int a = 10/3;

printf("%d",a);

return 0;

}

a)

3.33

b)

3.0

c)

3

d)

0

33.

Which of the following correctly shows the hierarchy of arithmetic operations in C?

a)

/ + * -

b)

* - / +

c)

+ - / *

d)

/ * + -

34.

To print out 'a' as an integer and 'b' as a decimal, which of the following printf() statement will you use?

a)

printf("%f %lf", a, b)

b)

printf("%f %f", a, b)

c)

printf("%d %f", a, b)

d)

printf("%f %d", a, b)

35.

Which of the following is not logical operator?

a)

&

b)

&&

c)

||

d)

!

36.

When does the code block following while(x<100) execute?

a)

When x is less than one hundred

b)

When x is greater than one hundred

c)

When x is equal to one hundred

d)

while it wishes

37.

Input/output function prototypes and macros are defined in which header file?

a)

conio.h

b)

stdlib.h

c)

stdio.h

d)

dos.h

38.

Which of the following is the correct operator to compare two variables?

a)

equal

b)

=

c)

:=

d)

==

39.

What is the only function all C programs must contain?

a)

start()

b)

system()

c)

main()

d)

Program()

40.

What punctuation is used to signal the beginning and end of code blocks?

a)

{ }

b)

-> and <-

c)

BEGIN and END

d)

( and )

41.

The "\n" character does which of the following operations?

a)

Double line spacing

b)

Character deletion

c)

Character backspace

d)

Places cursor on the next line

42.

Is the syntax for the following C statement correct?:


scanf("%d", input);

a)

True

b)

False

43.

Which arithmetic operator in C returns the integer remainder of the result of dividing its first operand by its second?

a)

%

b)

/

c)

\

d)

*

44.

Find the output in following code

int main ()

{

int a,b ;

a= b= 4 ;

b =a++;

Printf ( " %d %d %d %d", a++, --b, ++a, b--);

}

a)

5 3 73

b)

5 4 5 3

c)

6 2 6 4

d)

Syntax Error

45.

Find error/ output in following code

int main ()

{

int a = 10, b = 25;

a = b++ + a++;

b= ++b + ++a;

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

}

a)

36 64

b)

35 62

c)

36 63

d)

30 28

46.

Find error/output in following code

int main ()

{

int m = -10,n =20;

n = ( m < 0) ? 0 : 1;

printf ( " %d %d ", m,n ) ;

}

a)

-10 0

b)

10 20

c)

20 -10

d)

0 1

47.

Find Error/ output in following code

int main ()

{

int x = 1;

While (x= 0)

printf (" Hello");

}

a)

Hello

b)

No output

c)

Infinite time Hello display

d)

Error in code

48.
How will you print \n on the screen?
a)
printf("\n");
b)
echo "\\n";
c)
printf('\n');
d)
printf("\\n");
49.

1. What will be the output of following program?

a)

1 2 3 4 5

b)

1 2 3 4

c)

6

d)

5

50.

What will be the output of the program?

a)

Compiler error

b)

10 10 10 10 10

c)

11 12 13 14 15

d)

None of the above

51.

What will be the output of the program?

a)

No Output

b)

32 33 34

c)

32 33 34 35

d)

Compiler error

52.

What is the output of this program?

a)

32

b)

33

c)

30

d)

No Output

53.

Which of the given statement is true about the given code ?

a)

RABBIT is printed unlimited number of times

b)

RABBIT

c)

Compiler error

d)

None of the above.

54.

What will be the output of following program ?

a)

RABBIT

b)

RABBIT is printed unlimited number of times.

c)

No Output

d)

Compiler error.

55.

How many times i value is checked in the following C code?

a)

2

b)

3

c)

4

d)

1

56.

How many times i value is checked in the following C code?

a)

2

b)

3

c)

4

d)

1

57.

What will be the output of following program ?

a)

H

b)

H is printed infinite times

c)

Compile time error

d)

No output

58.

Which of the following is not a valid variable name declaration?

a)

int a3;

b)

int 3a;

c)

int _A3;

d)

int a_3

59.

All keywords in C are in ____________

a)

Lowercase

b)

Uppercase

c)

Camelcase

d)

None of these

60.

A translator which reads an entire program written in a high level language and converts it into machine language code is:

a)

Assembler

b)

Compiler

c)

Linker

d)

Loader

61.

Diamond shaped symbol is used in flowcharts to show the-

a)

decision box

b)

statement box

c)

error box

d)

if-statement box

62.

Which is valid C variable declarations?

a)

int my_num = 100,000;

b)

int my_num = 100000;

c)

int my num = 1000;

d)

int $my_num = 10000;

63.

Which is correct with respect to size of the data types?

a)

char > int > float

b)

int > char > float

c)

char < int < double

d)

double > char > int

64.

The functions printf() and scanf() are defined in which of the following library file:-

a)

math.h

b)

conio.h

c)

stdio.h

d)

stdlib.h

65.

Who developed C language

a)

Dennis Ritchie

b)

Bill Gates

c)

Dennis Lilly

d)

Stephen