wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Programming Skills C/C++

Total questions: 25

Worksheet time: 25mins

Name
Class
Date
1.

A C Variable cannot start with

a)

A- A number

b)

B- A special symbol other than underscore

c)

C- Both A and B

d)

D- An Alphabet

2.

Find the output of the following program-

void main()

{

int i=01289;

printf("%d",i);

}

a)

0289

b)

1289

c)

713

d)

Syntax Error

3.

What is the difference between a declaration and a definition of a variable?

a)

Both can occur multiple times, but a declaration must occur first.

b)

A definition occurs once, but a declaration may occur many times.

c)

Both can occur multiple times, but a definition must occur first.

d)

A declaration occurs once, but a definition may occur many times.

4.

what will be printed by the following code?

void main()

{

short testarray[4][3] = { {1}, {2,3}, {4,5,6}};

printf("%d", sizeof(testarray));

}

Assuming a short is two bytes long.

a)

24

b)

18

c)

12

d)

6

5.

How many times the program will print "SAIT Indore" ?

#include<stdio.h>;

int main()

{

printf("SAIT Indore");

main();

return 0;

}

a)

Infinite times

b)

32767 times

c)

65535 times

d)

Till stack overflows

6.

The value printed by the following program is …………?

void f(int *p, int m)

{

m = m + 5;

p= p + m;

return;

}

void main()

{

int i=10, j=20;

f(&i , j)

printf(“%d”, i+j);

}

a)

50

b)

45

c)

55

d)

60

7.

What would be the output of the following program.

#include<stdio.h>

main()

{

printf(“%d, %d”, sizeof(NULL), sizeof(‘ ‘));

}

a)

2, 1

b)

2, 2

c)

0, 1

d)

0, 2

8.

What will be output if you will compile and execute the following c code?

void main()

{

int i=320;

char ptr=(char )&i;

printf("%d",*ptr);

}

a)

320

b)

1

c)

64

d)

Complier Error

9.

What will be output if you will compile and execute the following c code?

#define x 5+2

void main()

{

int i;

i=x*x*x;

printf("%d", i);

}

a)

343

b)

27

c)

133

d)

Comipler error

10.

What will be output if you will compile and execute the following c code?

void main()

{

int i=4,x;

x=++i + ++i + ++i;

printf("%d",x);

}

a)

21

b)

18

c)

12

d)

Compiler error

11.

What will be output if you will compile and execute the following c code?

void main()

{

   char *str="Hello world";

   printf("%d",printf("%s",str));

}

a)

11Hello world

b)

10Hello world

c)

Hello world11

d)

Hello world10

12.

What will be output if you will compile and execute the following c code?

void main()

{

   float a=5.2;

  if(a==5.2)

     printf("Equal");

  else if(a<5.2)

     printf("Less than");

  else

     printf("Greater than"); 

}

a)

Equal

b)

Less than

c)

Greater than

d)

Compiler error

13.

What will be output if you will compile and execute the following c code?

#include <stdio.h>;

void main()

{

   int i=0;

for(;i<=2;)

  printf("%d",++i); 

}

a)

012

b)

0123

c)

123

d)

Compiler error

14.

What will be output if you will compile and execute the following c code?

void main()

{

   int x;

  for(x=1;x<=5;x++);

    printf("%d",x); 

}

a)

4

b)

5

c)

6

d)

Compiler error

15.

What does the following declaration mean?

int (*ptr)[10];

a)

ptr is array of pointers to 10 integers

b)

ptr is a pointer to an array of 10 integers

c)

ptr is an array of 10 integers

d)

ptr is an pointer to array

16.

What will be output if you will compile and execute the following c code?

void main()

{

double far* p,q;

printf("%d",sizeof(p)+sizeof q);

}

a)

4

b)

8

c)

12

d)

1

17.

#include<stdio.h>

main()

{

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

printf("%d", a[a[0]]);

}

a)

0

b)

1

c)

2

d)

Compile error

18.

What is the output of the following program?

#include<stdio.h>

main()

{

char s[] = "Fine";

*s = 'N';

printf("%s", s);

}

a)

Nine

b)

Fine

c)

Compile error

d)

Runtime error

19.

What is the output of the below code snippet?

#include<stdio.h>

main()

{

for(1;2;3)

printf("Hello");

}

a)

Infinite loop

b)

Prints “Hello” once.

c)

No output

d)

Compile error

20.

What is the output of the following statement?

#include<stdio.h>

main()

{

printf("%d", !0<2);

}

a)

True

b)

False

c)

1

d)

0

21.

What will be output of following c program?

#include<stdio.h>

int main()

{

enum number { a=-1, b= 4,c,d,e};

printf("%d",e);

return 0;

}

a)

5

b)

7

c)

4

d)

Garbage Value

22.

What will be the output of the program?

#include<stdio.h>

#define MAN(x, y) ((x)>(y)) ? (x):(y);

int main()

{

int i=10, j=5, k=0;

k = MAN(++i, j++);

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

return 0;

}

a)

12, 6, 12

b)

11, 6, 11

c)

11, 5, 11

d)

12, 6, Garbage

23.

Comment on the output of this C code?

#include <stdio.h>

void func();

int main()

{

static int b = 20;

func();

}

void func()

{

static int b;

printf("%d", b);

}

a)

Output will be 0

b)

Output will be 20

c)

Output will be garbage value

d)

Compile time error due to redeclaration of static variable

24.

What is the output of this C code?

#include <stdio.h>

#include <math.h>

void main()

{

int k = sqrt(-4);

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

}

a)

-2

b)

2

c)

Compile time error

d)

None the above

25.

What is the output of this C code?

#include<stdio.h>

void main()

{

register int x;

printf("%d", x);

}

a)

0

b)

1

c)

Compile time error

d)

Junk value