wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

C BASIC&OPERATORSQUIZFINAL

Total questions: 60

Worksheet time: 3600secs

Name
Class
Date
1.

What is the entry point of a C program?

a)

start()

b)

begin()

c)

main()

d)

program()

2.

Which of the following is a valid identifier in C?

a)

2variable

b)

variable_name

c)

var-name

d)

var name

3.

Which of the following is not a valid identifier?

a)

myVar

b)

_var123

c)

123var

d)

var_123

4.

Which of the following is a keyword in C?

a)

function

b)

define

c)

return

d)

begin

5.

Which of the following is the correct way to declare a variable in C?

a)

int variable;

b)

int variable:

c)

int variable{};

d)

int variable()

6.

Which of the following is true about variables in C?

a)

Variables can be declared without specifying a data type.

b)

Variable names can start with a digit.

c)

Variables can be declared anywhere in the program before they are used.

d)

Variables do not need to be initialized before use.

7.

Which of the following is not a basic data type in C?

a)

int

b)

float

c)

double

d)

string

8.

Which of the following data types has the highest precision?

a)

int

b)

float

c)

double

d)

char

9.

Which function is used to read formatted input from the standard input in C?

a)

printf()

b)

scanf()

c)

gets()

d)

puts()

10.

Which of the following format specifiers is used to print a floating-point number?

a)

%d

b)

%c

c)

%f

d)

%s

11.

Which of the following code snippets contains a valid identifier?

#include <stdio.h>

int main() {

    int 1variable = 10;

    printf("%d\n", 1variable);

    return 0;

}

a)

The code contains a valid identifier.

b)

The code does not contain a valid identifier.

12.

Which of the following code snippets correctly uses a keyword in C?

#include <stdio.h>

int main() {

    int return = 10;

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

    return 0;

}

a)

The code correctly uses a keyword.

b)

The code does not correctly use a keyword.

13.

What will be the output of the following C program?

#include <stdio.h>

int main() {

    double num = 5.25;

    printf("Value = %.2f\n", num);

    return 0;

a)

Value = 5.2

b)

Value = 5.25

c)

Value = 5

d)

Value = 5.250000

14.

What will be the output of the following C program?

#include <stdio.h>

int main() {

    int a = 5;

    float b = 5.5;

    printf("a = %d, b = %.1f\n", a, b);

    return 0;

}

a)

a = 5, b = 5

b)

a = 5, b = 5.5

c)

a = 5, b = 5.50

d)

The code will produce a compilation error.

15.

What will be the output of the following C program?

#include <stdio.h>

int main() {

    float a = 7.0;

    int b = 2;

    float result = a / b;

    printf("Result = %.1f\n", result);

    return 0;

}

a)

Result = 3

b)

Result = 3.5

c)

Result = 3.0

d)

The code will produce a compilation error.

16.

What will be the output of the following C program?

 #include <stdio.h>

   int main() {

       int a = 10;

       int b = a;

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

       return 0;

   }

 

a)

10

b)

0

c)

Garbage value

d)

Compilation error

17.

What will be the output of the following C program?

 int main() {

       int a = 5, b = 3;

       int result = a + b * 2;

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

       return 0;

   }

 

a)

16

b)

13

c)

11

d)

10

18.

What will be the output of the following C program?#include <stdio.h>

   int main() {

       int a = 5, b = 3;

       int result = (a > b) && (a < 10);

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

       return 0;

   }

  

a)

0

b)

1

c)

3

d)

5

19.

#include int main() { int x = 10, y = 5, z = 0; z = x++ + ++y; printf("%d", z); return 0; }

a)

15

b)

16

c)

17

d)

18

20.

What is the output of the following code? #include int main() { int a = 7, b = 3; printf("%d", a / b); return 0; }

a)

2

b)

2.33

c)

3

d)

3.5

21.

What will be the output of the following code? #include int main() { int a = 5; printf("%d", a == 5); return 0; }

a)

0

b)

1

c)

5

d)

-1

22.

Which of the following is the correct order of precedence (from highest to lowest) of the given operators?

a)

+, *, &&, ||

b)

*, +, &&, ||

c)

&&, ||, +, *

d)

||, &&, +, *

23.

What will be the output of the following code? #include int main() { int a = 5, b = 3; printf("%d", a & b); return 0; }

a)

1

b)

2

c)

3

d)

5

24.

What is the output of the following code? #include int main() { int a = 10, b = 20, c = 30; printf("%d", (a < b) && (b > c) || (a == c)); return 0; }

a)

0

b)

1

c)

-1

d)

10

25.

What is the output of the following code? #include int main() { int a = 5, b = 10, c; c = (a > b) ? (a - b) : (b - a); printf("%d", c); return 0; }

a)

5

b)

10

c)

-5

d)

0

26.

What will be the result of the following expression in C? int a = 5; float b = 2.5; float c = a + b;

a)

7.5

b)

7

c)

5.0

d)

Compilation error

27.

What happens when an int and a double are used together in an arithmetic expression?

a)

The int is promoted to a double

b)

The double is demoted to an int

c)

The result is always an int

d)

Compilation error

28.

What will happen if we assign a float value to an int variable?

a)

The value will be rounded off

b)

The value will be truncated

c)

The value will remain the same

d)

Compilation error

29.

What is the result of the following code? float a = 9.8; int b = (int)a;

a)

9.8

b)

10

c)

9

d)

Compilation error

30.

What does the following expression evaluate to? int a = 7; int b = 2; double c = (double)(a / b);

a)

3.5

b)

3.0

c)

3

d)

Compilation error

31.

What will be the result of this code? double x = -7.999; int y = (int)x;

a)

-8

b)

-7

c)

-7.999

d)

Compilation error

32.

#include main() { int a=012,b=034; int x=0x12,y=0x34; int c,d,u,v; c=a&&b; d=a||b; u=x&&y; v=x||y; printf("%d%d%d%d",c,d,u,v); }

4 lines
33.

What will be the output of the following 'C' code? void main ( ) { int x = 128; printf ("\n%d", 1 + x ++); }

a)

128

b)

129

34.

What will be the output of the following 'C' code? #include void main() { int a=30,b=40,x; x=(a!=10) && (b=50); printf("%d",x); }

a)

0

b)

1

35.

What will be the output of the following 'C' code? #include int main() { int x= -7 - -9; int y= -7 - -(-9); printf("x=%d\ny=%d\n",x,y); return 0; }

a)

x=2 y=-16

b)

x=-2 y=16

36.

What will be the output of the following 'C' code? #include int main() { int x; x= 9 % 5 * 4; printf("x=%d",x); return 0; }

a)

x=16

b)

x=4

37.

What will be the output of the following 'C' code? #include int main() { int x; x= 4 - 6 * 5/5 + 7 % 2;; printf("x= %d",x); return 0; }

a)

x=-1

b)

x=1

38.

What will be the output of the following 'C' code? #include int main() { int a; float b ; a=9 % 4; b= 9 % 4; printf("%d, %f \n",a,b); return 0; }

a)

1, 1.000000

b)

0, 0.000000

39.

What will be the output of the following 'C' code? #include int main() { int a; a=5^ 8-3*2; printf("%d",a); return 0; }

a)

7

b)

1

40.

What will be the output of the following 'C' code? #include int main() { int x=10,y=-20; x=!x; y=!y; printf("x= %d, y= %d", x,y); return 0; }

a)

x= 0, y= 0

b)

x= 1, y= 1

41.

What will be the output of the following 'C' code? #include int main() { int x=3,y=4,z=4; printf("ans= %d", z>=y&&y>=x?1:0); return 0; }

a)

ans= 1

b)

ans= 0

42.

What will be the output of the following 'C' code? #include int main() { int x=3,y=4,z=4; printf("ans= %d", (z>=y>=x?100:200)); return 0; }

a)

ans= 100

b)

ans= 200

43.

What will be the output of the following 'C' code? #include int main() { int a=10,b=10; printf("ans= %d",a>b?a*a:b/b); return 0; }

a)

ans= 1

b)

ans= 0

44.

What will be the output of the following 'C' code? #include int main() { int a=10,b=20,c=30; c=(10,20)==(c,b); printf("%d",c); return 0; }

a)

ans= 1

b)

ans= 0

45.

What will be the output of the following 'C' code? #include int main() { int a=10,b=20,c=30; c==a==b; printf("%d%d%d",a,b,c); return 0; }

a)

10 20 30

b)

10 20 0

46.

What will be the output of the following 'C' code? #include int main() { int k=12,n=30; k=(n=4 && n==4?100:200); printf("k= %d",n) ; return 0; }

a)

k= 200

b)

k= 100

47.

What will be the output of the following 'C' code? #include int main() { int a=10,b=20,c=30; printf("ans= %d",a>b? a>c?a:c : b>c?b:c); return 0; }

a)

ans= 30

b)

ans= 20

48.

What will be the output of the following 'C' code? #include int main() { int a=5,b=10; a+=b; printf("%d",a); return 0; }

a)

15

b)

5

49.

What will be the output of the following 'C' code? #include int main() { int x=2,y=3; printf("%d",x*y++); return 0; }

a)

9

b)

6

50.

#include main()

{ int i=10,j; j=++i++; printf("%d%d",i,j); }

4 lines
51.

#include main()

{ inti=10,j=11,k,l; k=i+++j; l=i+++++j; printf("%d%d",l,k); }

4 lines
52.

#include main()

{ int x=20,y=35; x=y++ + x++; y=++y + ++x; printf("%d%d",x,y); }

4 lines
53.

#include main()

{ int i=0,j=1,k=2,l; l=++i&&j++||++k; printf("%d %d %d %d",i,j,k,l); }

4 lines
54.

#include main()

{ float a=0.5; int c; c=a<0.5; printf("%d",c); }

4 lines
55.

#include main()

{ int a=0,b=0; ++a==0||++b==||; printf("%d%d",a,b); }

4 lines
56.

#include main()

{ int c=- -2; printf("%d",c); }

4 lines
57.

#include main()

{ int i=5; printf("%d%d%d%d%d",i++,i--,++i,--i,i); }

4 lines
58.

#include int main()

{ int a = 2,b = 5; a = a^b; b = b^a; printf("%d %d",a,b); return 0; }

4 lines
59.

#include int main()

{ int a = 2,b = 5; a = a^b; b = b^a; printf("%d %d",a,b); return 0; }

4 lines
60.

#include int main() { printf(" \"%%d %%f\"",123,123.2); }

4 lines