wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

C Programming Quiz

Total questions: 20

Worksheet time: 10mins

Name
Class
Date
1.

what is output of this code? #include int main() { printf("%c ", 5["GeeksQuiz"]); return 0; }

a)

Compile-time error

b)

Runtime error

c)

Q

d)

s

2.

Which of the following is true

a)

gets() can read a string with newline characters but a normal scanf() with %s can not.

b)

gets() can read a string with spaces but a normal scanf() with %s can not.

c)

gets() can always replace scanf() without any additional code.

d)

None of the above

3.

Which of the following functions from “stdio.h” can be used in place of printf()?

a)

fputs() with FILE stream as stdout.

b)

fprintf() with FILE stream as stdout.

c)

fwrite() with FILE stream as stdout.

d)

All of the above three - a, b and c.

e)

In “stdio.h”, there’s no other equivalent function of printf().

4.

Which of the following is not a valid declaration in C?

a)

3 and 4

b)

short int x;

c)

short x;

d)

unsigned short x;

e)

signed short x;

5.

In C, sizes of an integer and a pointer must be same.

a)

True

b)

False

6.

Suppose a C program has floating constant 1.414, what's the best way to convert this as "float" data type?

a)

(float)1.414

b)

float(1.414)

c)

1.414f or 1.414F

d)

1.414 itself of "float" data type i.e. nothing else required.

7.

What is output? #include int main(void) { int a = 1; int b = 0; b = a++ + a++; printf("%d %d",a,b); return 0; }

a)

3 6

b)

Compiler Dependent

c)

3 4

d)

3 3

8.

In C, two integers can be swapped using minimum

a)

0 extra variable

b)

1 extra variable

c)

2 extra variable

d)

4 extra variable

9.

Which of the following operators cannot be overloaded in C/C++ ?

a)

Bitwise right shift assignment

b)

Address of

c)

Indirection

d)

Structure reference

e)

Discuss it

10.

What is the output of code? #include int main() { printf("%d", printf("%d", 1234)); return 0; }

a)

12344

b)

12341

c)

11234

d)

41234

11.

What is the return type of getchar()?

a)

int

b)

char

c)

unsigned char

d)

float

12.

What is the output of code? #include int main() { if (sizeof(int) > -1) printf("Yes"); else printf("No"); return 0; }

a)

Yes

b)

No

c)

Compiler Error

d)

Runtime Error

13.

What is the output? #include "stdio.h" int main() { int a = 10; int b = 15; printf("=%d",(a+1),(b=a+2)); printf(" %d=",b); return 0; }

a)

=11 15=

b)

=11 12=

c)

Compiler Error due to (b=a+2) in the first printf().

d)

No compile error but output would be =11 X= where X would depend on compiler implementation.

14.

#include int main() { int x = 128; printf("\n%d", 1 + x++); return 0; }

a)

128

b)

129

c)

130

d)

131

15.

#include 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

16.

#include int main() { short a = 320; char * ptr; ptr = (char * ) & a; printf("%d", * ptr); return 0; }

a)

1

b)

320

c)

64

d)

Compilation error

17.

#include int main() { static int i=5; if (--i){ printf("%d ",i); main(); } }

a)

4 3 2 1

b)

1 2 3 4

c)

4 4 4 4

d)

0 0 0 0

18.

#include int main() { int x = 5; int * const ptr = &x; ++(*ptr); printf("%d", x); return 0; }

a)

Compiler Error

b)

Runtime Error

c)

6

d)

5

19.

#include int main() { int x = 10; static int y = x; if(x == y) printf("Equal"); else if(x > y) printf("Greater"); else printf("Less"); return 0; }

a)

Compiler Error

b)

Equal

c)

Greater

d)

Less

20.

What is output of following code ?

// C program to demonstrate shallow copy

# include <stdio.h>

# include <string.h>

# include <stdlib.h>

struct test

{

char *str;

};

int main()

{

struct test st1, st2;

st1.str = (char )malloc(sizeof(char) 20);

strcpy(st1.str, "GeeksforGeeks");

st2 = st1;

st1.str[0] = 'X';

st1.str[1] = 'Y';

/* Since copy was shallow, both strings are same */

printf("st1's str = %s\n", st1.str);

printf("st2's str = %s\n", st2.str);

return 0;

}

a)

st1's str = XYeksforGeeks

st2's str = XYeksforGeeks

b)

st1's str = XYeksforGeek

st2's str = XYeksforGeek

c)

st1's str = XYeksforGeeks

//st2's str = XYeksforGeeks

d)

//st1's str = XYeksforGeeks

st2's str = XYeksforGeeks