wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Quiz on c program

Total questions: 50

Worksheet time: 50mins

Name
Class
Date
1.

What is a correct syntax to output "Hello World" in C

a)

Console.WriteLine(“Hello World”);


b)

System.out.println(“Hello World”);


c)

cout<<”Hello World”;

d)

printf(“Hello World”);


2.

How do you insert COMMENTS in C code?

a)

— This is a comment


b)

# This is a comment


c)

// This is a comment


d)

* This is a comment


3.

When a variable is created in C, a memory address is assigned to the variable.


a)

True

b)

False

4.

In C, code statements must end with a semicolon (;)


a)

True

b)

False

5.

How can you create a variable with the numeric value 5?


a)

val num = 5;

b)

num = 5;


c)

num = 5 int;


d)

int num = 5;


6.

How can you create a variable with the floating number 2.8?


a)

float num=2.8;


b)

val num = 2.8;


c)

num=2.8 float;


d)

num=2.8 double;

7.

 Which operator is used to add together two values?


a)

The & sign

b)

The ADD keyword


c)

The * sign

d)


The + sign


8.

 Which function is often used to output and print values?


a)

printword()


b)

printf()


c)

write()


d)

output()


9.

 Which format specifier is often used to print integers?


a)

%s

b)

%c


c)

%d


d)

%f


10.

Which operator can be used to compare two values?


a)

==


b)

=


c)

<>


d)

><

11.

#include <stdio.h>

int main()

{

float q = ‘a’;

printf(“%f”, q);

return 0;

}


a)

 run time error


b)

a


c)

97.000000


d)

a.0000000


12.

Which of these is NOT a relational or logical operator?


a)

 =


b)

 ||


c)

 ==


d)

 !=


13.

 What is a short int in C programming?


a)

The basic data type of C


b)

Qualifier


c)

Short is the qualifier and int is the basic data type


d)

All of the mentioned


14.

Predict the output of following C program

#include <stdio.h>

int main()

{

  char a = 012;

  printf("%d", a);

  return 0;

}


a)

Compiler Error


b)

12

c)

10

d)

Empty

15.

The format identifier ‘%i’ is also used for _____ data type.


a)

char

b)

int

c)

float

d)

double

16.

A long integer is at least 32 bits wide and a short integer is at least 16 bits wide


a)

True

b)

False

17.

Which operator can be used to find the memory size (in bytes) of a data type or variable?


a)

length()


b)

size()


c)

 sizeof()


d)

length()


18.

Which keyword can be used to make a variable unchangeable?


a)

const

b)

constant


c)

readonly

d)

final


19.

Who is the father of C language?


a)

 Steve Jobs


b)

James Gosling


c)

Dennis Ritchie


d)

Rasmus Lerdorf


20.

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


a)

 int number;


b)

 float rate;



c)

int variable_count;

d)

 int $main;

21.

All keywords in C are in ____________


a)

LowerCase letters


b)

UpperCase letters


c)

CamelCase letters


d)

None of the mentioned


22.

Which is valid C expression?



a)

 int my_num = 100,000;


b)

int my_num = 100000;


c)

int my num = 1000;


d)

int $my_num = 10000;

23.

 Which of the following cannot be a variable name in C?


a)

volatile


b)

true

c)

friend

d)

export

24.

Which keyword is used to prevent any changes in the variable within a C program?


a)

immutable


b)

mutable


c)

const


d)

volatile


25.

The C-preprocessors are specified with _________ symbol.


a)

#

b)

$

c)

" '

d)

&

26.

When was C programming developed?


a)

The 1950s


b)

The 1960s

c)

The 1980s


d)

The 1970s


27.

What was C programming adapted from?


a)

C++


b)

Combined programming language

c)

python


d)

All of the above


28.

#include <stdio.h>

int main()

{

  int i;

  i = 1, 2, 3;

  printf("%d", i);

  return 0;

}

output..........?


a)

1

b)

3

c)

Garbage value

d)

compile time error

29.

What is the output of the below program?

#include <stdio.h>

int main() {

  int i = 2;

  switch (i) {

    case 0:

      printf("CSIT");

      break;

    case 1:

      printf("CSD");

      break;

    default:

      printf("CSE");

  }

  return 0;

}


a)

CSIT

b)

CSD

c)

CSE

d)

compile time error

30.

#include <stdio.h>

int i;

int main() {

  if (printf(“Hi”)) {

    i=2;

  } else {

    printf("Else");

  }

  return 0;

}

What is the output of above program?


a)

Else


b)

Compilation error


c)

Hi


d)

Error: misplaced else

31.

#include <stdio.h>

int main()

{

 int a = 10, b = 20, c = 30;

 if (c > b > a)

  printf("TRUE");

 else

  printf("FALSE");

 return 0;

}


a)

TRUE

b)

FALSE

c)

Wrong

d)

Compile time error

32.

Which statement is used to make decisions in C?


a)

loop

b)

if

c)

print

d)

return

33.

What will the following code output? 

if (5 > 3) {

printf("True");

else {

printf("False");

}


a)

True

b)

False

c)

Errror

d)

None

34.

What does the else statement do?


a)

Executes if the condition is true


b)

Executes if the condition is false


c)

Always executes


d)

None of the above


35.

Which of the following is a valid syntax for a switch statement?


a)

switch (expression) { case: }


b)

switch { expression }


c)

 switch (expression) { case value: }


d)

 switch (case value) { expression }


36.

What will be the output of this code? 

int x = 10; 

if (x < 5) {

printf("Low");

}

 else {

printf("High");

}


a)

Low


b)

High

c)

Error

d)

None

37.

In C, what does the ternary operator do?


a)

Repeats a statement


b)

Evaluates a condition and returns one of two values


c)

Defines a function


d)

None of the above


38.

Which of the following is true about the switch statement?


a)

It can evaluate conditions of different types


b)

It can have multiple default cases


c)

 It can include break statements


d)

 It requires a boolean expression


39.

What is the purpose of the break statement in a loop or switch?


a)

To pause execution


b)

To exit the loop or switch


c)

To skip the current iteration


d)

To repeat the statement


40.

What happens if no case matches in a switch statement?


a)

An error occurs


b)

The program crashes


c)

The default case is executed, if it exists


d)

Nothing happens


41.

Which of the following is not a conditional statement in C?

a)

if

b)

else

c)

for

d)

switch

42.

What will be the output of the following C code?

#include <stdio.h>

int main()

{

int a = 10;

if (a == a--)

printf("TRUE 1\t");

a = 10;

if (a == --a)

printf("TRUE 2\t");

}


a)

TRUE 1


b)

TRUE 2


c)

TRUE 1 TRUE 2


d)

Compiler Dependent


43.

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

 #include <stdio.h>

 int main()

{

int a = 10, b = 5, c = 5;

int d;

d = b + c == a;

printf("%d", d);

}


a)

Syntax error


b)

1

c)

5

d)

10

44.

Output of following program?

#include<stdio.h>

int main()

{

  float x = 0.1;

  if ( x == 0.1 )

    printf("IF");

  else if (x == 0.1f)

    printf("ELSE IF");

  else

    printf("ELSE");

}


a)

ELSE IF


b)

IF


c)

 ELSE


d)

compile error


45.

What is the result of logical or relational expression in C?


a)

 True or False


b)

0 or 1


c)

0 if an expression is false and any positive number if an expression is true


d)

None of the mentioned


46.

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

 #include <stdio.h>

void main()

{

 int x = 5 * 9 / 3 + 9;

}


a)

 3.75


b)

Depends on compiler


c)

3

d)

24

47.

Which operator is used for incrementing a variable by 1?


a)

--

b)

++

c)

+=

d)

=

48.

What is an example of iteration in C?


a)

 for


b)

while

c)

do-while

d)

all of the mentioned


49.

What will be the output of the following C code?

#include <stdio.h>

int main()

{

int i = -3;

 int k = i % 2;

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

 }


a)

Compile time error


b)

-1

c)

1

d)

 Implementation defined


50.

What does the '&&' operator represent?


a)

Logical OR


b)

Bitwise AND


c)

Logical AND


d)

Bitwise OR