wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Test 1 - 23CS1005 Programming for Problem Solving

Total questions: 50

Worksheet time: 36mins

Name
Class
Date
1.

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

2.

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

3.

How many loops are there in C

a)

1

b)

3

c)

2

d)

4

4.

which is the only function all C programs must contain?

a)

start()

b)

sys()

c)

main()

d)

scanf()

5.

Which of the following is not a correct variable type?

a)

float

b)

real

c)

int

d)

double

6.

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

7.

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

8.

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

9.

Library function pow() belongs to which header file?

a)

math.h

b)

square.h

c)

stdio.h

d)

conio.h

10.

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

a)

yes

b)

no

c)

may be

11.

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

a)

1

b)

2

c)

no limit

d)

depends on the program

12.

int x = 10;


int main()

{

int x = 0;

printf("%d",x);

return 0;

}

a)

10

b)

0

c)

compile error

d)

undefined

13.

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

14.

C programs are converted into machine language with the help of

a)

An Editor

b)

A compiler

c)

An operating system

d)

None of these.

15.

Which one of the following is not a valid identifier?

a)

_examveda

b)

1examveda

c)

exam_veda

d)

examveda1

16.

Which is the only function all C programs must contain?

a)

start()

b)

system()

c)

printf()

d)

main()

17.

int main ()

{

int x = 24, y = 39, z = 45;

z = x + y;

y = z - y;

x = z - y;

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

}

a)

24 39 63

b)

39 24 63

c)

24 39 45

d)

39 24 45

18.

A name having a few letters, numbers and special character _(underscore) is called

a)

keywords

b)

reserved keywords

c)

tokens

d)

identifiers

19.
What punctuation is used to indicate the beginning and end of code blocks?
a)
{ }
b)
-> <-
c)
BEGIN and END
d)
( and )
20.

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

a)

int a3;

b)

int 3a;

c)

int _A3;

d)

int a_3

21.

All keywords in C are in ____________

a)

Lowercase

b)

Uppercase

c)

Camelcase

d)

None of these

22.

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

23.

Diamond shaped symbol is used in flowcharts to show the-

a)

decision box

b)

statement box

c)

error box

d)

if-statement box

24.

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

25.

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;

26.

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

27.

Which is variable declaration?

a)

int a,b;

b)

c=a+b;

c)

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

d)

scanf("%d%d",&a,&b);

28.

how to print a and b variable of int and float respectively

a)

scanf("%d%f",&a,&b);

b)

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

c)

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

d)

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

29.

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!

30.

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

a)

char

b)

int

c)

float

d)

double

31.

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

32.

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

33.

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

34.

Find error/ output in following code

int main ()

{

int i = 0;

for ( ; ;)

printf ( "%d", i) ;

return 0;

}

a)

O times

b)

Infinite times

c)

10 times

d)

1 times

35.

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

36.

Find Error/ output in following code

Void main ()

{

printf ( " % d " , printf ( " computer science"));

}

a)

Computer science16

b)

16computer science

c)

Computer science

d)

Computer science18

37.

Point out the error in the program

f ( int a, int b)

{

int a;

a = 20;

return a;

}

a)

Missing parentheses in return statement

b)

The function should be defined as int f ( int a, int b)

c)

Redeclaration of a

d)

None of the above

38.

What will be the output of following program?

a)

Hello

b)

OK

c)

Hello

OK

d)

Error

39.

What will be the output of the program?

a)

This is default

This is case 1

b)

This is case 3

This is default

c)

This is case 1

This is case 3

d)

This is default

40.

What will be the output of following program ?

a)

Hello

b)

ERROR

c)

No Output

d)

Garbage Value

41.

The keyword break cannot be simply used within

a)

while statements

b)

for statement

c)

if else

d)

do while

42.

switch statement accept

a)

int

b)

char

c)

long

d)

all

43.

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

a)

/ + * -

b)

* - / +

c)

+ - / *

d)

/ * + -

44.

Which of the following is not logical operator?

a)

&

b)

&&

c)

||

d)

!

45.

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

46.

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

a)

conio.h

b)

stdlib.h

c)

stdio.h

d)

dos.h

47.

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

a)

equal

b)

=

c)

:=

d)

==

48.

What is the only function all C programs must contain?

a)

start()

b)

system()

c)

main()

d)

Program()

49.

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

50.

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

a)

%

b)

/

c)

\

d)

*