Fatskills
Practice. Master. Repeat.
Study Guide: Fundamentals of C Programming: 490 Solved Multiple Choice Questions (MCQs)
Source: https://www.fatskills.com/c-programming/chapter/fundamentals-of-c-programming-solved-multiple-choice-questions-mcqs

Fundamentals of C Programming: 490 Solved Multiple Choice Questions (MCQs)

By Fatskills Exam Guides Team — the exam nerds behind 28,500+ quizzes and 2.1M practice questions across 500+ global exams.

⏱️ ~42 min read

490 Solved Multiple Choice Questions (MCQs) on Fundamentals of C Programming.

Topics covered:
1. Fundamentals of C Programming
2. Operators & Preceedence
3. Control Structures, Branching & Looping
4. Functions
5. Arrays & Strings
6. Structure and Union
7. Pointers

 

 

Part 1: Fundamentals of C Programming

 

 

1. C99 standard guarantees uniqueness of __________ characters for internal names.
a) 31
b) 63
c) 12
d) 14
Answer: b
Explanation: ISO C99 compiler may consider only first 63 characters for internal names.

 

 

2. C99 standard guarantees uniqueness of ___________ characters for external names.
a) 31
b) 6
c) 12
d) 14
Answer: a
Explanation: ISO C99 compiler may consider only first 31 characters for external names.

 

 

3. Which of the following is not a valid variable name declaration?
a) int __a3;
b) int __3a;
c) int __A3;
d) None of the mentioned
Answer: d
Explanation: None.

 

 

4. Which of the following is not a valid variable name declaration?
a) int _a3;
b) int a_3;
c) int 3_a;
d) int _3a
Answer: c
Explanation: Variable name cannot start with a digit.

 

 

5. Why do variable names beginning with the underscore is not encouraged?
a) It is not standardized
b) To avoid conflicts since assemblers and loaders use such names
c) To avoid conflicts since library routines use such names
d) To avoid conflicts with environment variables of an operating system
Answer: c
Explanation: None.

 

 

6. All keywords in C are in ____________
a) LowerCase letters
b) UpperCase letters
c) CamelCase letters
d) None of the mentioned
Answer: a
Explanation: None.

 

 

7. Variable name resolution (number of significant characters for the uniqueness of variable) depends on ___________
a) Compiler and linker implementations
b) Assemblers and loaders implementations
c) C language
d) None of the mentioned
Answer: a
Explanation: It depends on the standard to which compiler and linkers are adhering.

 

 

8. Which of the following is not a valid C variable name?
a) int number;
b) float rate;
c) int variable_count;
d) int $main;
Answer: d
Explanation: Since only underscore and no other special character is allowed in a variable name, it results in an error.

 

 

9. Which of the following is true for variable names in C?
a) They can contain alphanumeric characters as well as special characters
b) It is not an error to declare a variable to be one of the keywords(like goto, static)
c) Variable names cannot start with a digit
d) Variable can be of any length
Answer: c
Explanation: According to the syntax for C variable name, it cannot start with a digit.

 

 

10. 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;
Answer: b
Explanation: Space, comma and $ cannot be used in a variable name.

 

 

11. What will be the output of the following C code?

 

#include
int main()
{
printf(“Hello World! %d \n”, x);
return 0;
}
a) Hello World! x;
b) Hello World! followed by a junk value
c) Compile time error
d) Hello World!
Answer: c
Explanation: It results in an error since x is used without declaring the variable x.
Output:
$ cc pgm1.c
pgm1.c: In function ‘main’:
pgm1.c:4: error: ‘x’ undeclared (first use in this function)
pgm1.c:4: error: (Each undeclared identifier is reported only once
pgm1.c:4: error: for each function it appears in.)

 

12. What will be the output of the following C code?

 

#include
int main()
{
int y = 10000;
int y = 34;
printf(“Hello World! %d\n”, y);
return 0;
}
a) Compile time error
b) Hello World! 34
c) Hello World! 1000
d) Hello World! followed by a junk value
Answer: a
Explanation: Since y is already defined, redefining it results in an error.
Output:
$ cc pgm2.c
pgm2.c: In function ‘main’:
pgm2.c:5: error: redefinition of ‘y’
pgm2.c:4: note: previous definition of ‘y’ was here

 

13. Which of the following is not a valid variable name declaration?
a) float PI = 3.14;
b) double PI = 3.14;
c) int PI = 3.14;
d) #define PI 3.14
Answer: d
Explanation: #define PI 3.14 is a macro preprocessor, it is a textual substitution.

 

 

14. What will happen if the following C code is executed?

 

#include
int main()
{
int main = 3;
printf(“%d”, main);
return 0;
}
a) It will cause a compile-time error
b) It will cause a run-time error
c) It will run without any error and prints 3
d) It will experience infinite looping
Answer: c
Explanation: A C program can have same function name and same variable name.
$ cc pgm3.c
$ a.out
3

 

15. What is the problem in the following variable declaration?
float 3Bedroom-Hall-Kitchen?;
a) The variable name begins with an integer
b) The special character ‘-‘
c) The special character ‘?’
d) All of the mentioned
Answer: d
Explanation: A variable name cannot start with an integer, along with that the C compiler interprets the ‘-‘ and ‘?’ as a minus operator and a question mark operator respectively.

 

 

16. What will be the output of the following C code?

 

#include
int main()
{
int ThisIsVariableName = 12;
int ThisIsVariablename = 14;
printf(“%d”, ThisIsVariablename);
return 0;
}
a) The program will print 12
b) The program will print 14
c) The program will have a runtime error
d) The program will cause a compile-time error due to redeclaration
Answer: b
Explanation: Variable names ThisIsVariablename and ThisIsVariableName are both distinct as C is case sensitive.
Output:
$ cc pgm4.c
$ a.out
14

 

17. Which of the following cannot be a variable name in C?
a) volatile
b) true
c) friend
d) export
Answer: a
Explanation: volatile is C keyword.

 

 

18. What will be the output of the following C code?

 

#include
int main()
{
int a[5] = {1, 2, 3, 4, 5};
int i;
for (i = 0; i < 5; i++)
if ((char)a[i] == ‘5’)
printf(“%d\n”, a[i]);
else
printf(“FAIL\n”);
}
a) The compiler will flag an error
b) The program will compile and print the output 5
c) The program will compile and print the ASCII value of 5
d) The program will compile and print FAIL for 5 times
Answer: d
Explanation: The ASCII value of 5 is 53, the char type-casted integral value 5 is 5 only.
Output:
$ cc pgm1.c
$ a.out
FAIL
FAIL
FAIL
FAIL
FAIL

 

19. The format identifier ‘%i’ is also used for _____ data type.
a) char
b) int
c) float
d) double
Answer: b
Explanation: Both %d and %i can be used as a format identifier for int data type.

 

 

20. Which data type is most suitable for storing a number 65000 in a 32-bit system?
a) signed short
b) unsigned short
c) long
d) int
Answer: b
Explanation: 65000 comes in the range of short (16-bit) which occupies the least memory. Signed short ranges from -32768 to 32767 and hence we should use unsigned short.

 

 

21. Which of the following is a User-defined data type?
a) typedef int Boolean;
b) typedef enum {Mon, Tue, Wed, Thu, Fri} Workdays;
c) struct {char name[10], int age};
d) all of the mentioned
Answer: d
Explanation: typedef and struct are used to define user-defined data types.

 

 

22. What is the size of an int data type?
a) 4 Bytes
b) 8 Bytes
c) Depends on the system/compiler
d) Cannot be determined
Answer: c
Explanation: The size of the data types depend on the system.

 

 

23. What will be the output of the following C code?

 

#include
int main()
{
signed char chr;
chr = 128;
printf(“%d\n”, chr);
return 0;
}
a) 128
b) -128
c) Depends on the compiler
d) None of the mentioned
Answer: b
Explanation: signed char will be a negative number.
Output:
$ cc pgm2.c
$ a.out
-128

 

24. What will be the output of the following C code?

 

#include
int main()
{
char c;
int i = 0;
FILE *file;
file = fopen(“test.txt”, “w+”);
fprintf(file, “%c”, ‘a’);
fprintf(file, “%c”, -1);
fprintf(file, “%c”, ‘b’);
fclose(file);
file = fopen(“test.txt”, “r”);
while ((c = fgetc(file)) != -1)
printf(“%c”, c);
return 0;
}
a) a
b) Infinite loop
c) Depends on what fgetc returns
d) Depends on the compiler
Answer: a
Explanation: None.
Output:
$ cc pgm3.c
$ a.out
a

 

25. What is 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
Answer: c
Explanation: None.

 

 

26. What will be the output of the following C code?

 

#include
int main()
{
float f1 = 0.1;
if (f1 == 0.1)
printf(“equal\n”);
else
printf(“not equal\n”);
}
a) equal
b) not equal
c) output depends on the compiler
d) error
Answer: b
Explanation: 0.1 by default is of type double which has different representation than float resulting in inequality even after conversion.
Output:
$ cc pgm4.c
$ a.out
not equal

 

27. What will be the output of the following C code?

 

#include
int main()
{
float f1 = 0.1;
if (f1 == 0.1f)
printf(“equal\n”);
else
printf(“not equal\n”);
}
a) equal
b) not equal
c) output depends on compiler
d) error
Answer: a
Explanation: 0.1f results in 0.1 to be stored in floating point representations.
Output:
$ cc pgm5.c
$ a.out
equal

 

28. What will be the output of the following C code on a 32-bit machine?

 

#include
int main()
{
int x = 10000;
double y = 56;
int *p = &x;
double *q = &y;
printf(“p and q are %d and %d”, sizeof(p), sizeof(q));
return 0;
}
a) p and q are 4 and 4
b) p and q are 4 and 8
c) compiler error
d) p and q are 2 and 8
Answer: a
Explanation: Size of any type of pointer is 4 on a 32-bit machine.
Output:
$ cc pgm6.c
$ a.out
p and q are 4 and 4

 

29. Which is correct with respect to the size of the data types?
a) char > int > float
b) int > char > float
c) char < int < double
d) double > char > int
Answer: c
Explanation: char has less bytes than int and int has less bytes than double in any system

 

 

30. What will be the output of the following C code on a 64 bit machine?

 

#include
union Sti
{
int nu;
char m;
};
int main()
{
union Sti s;
printf(“%d”, sizeof(s));
return 0;
}
a) 8
b) 5
c) 9
d) 4
Answer: d
Explanation: Since the size of a union is the size of its maximum data type, here int is the largest data type. Hence the size of the union is 4.
Output:
$ cc pgm7.c
$ a.out
4

 

31. What will be the output of the following C code?

 

#include
int main()
{
float x = ‘a’;
printf(“%f”, x);
return 0;
}
a) a
b) run time error
c) a.0000000
d) 97.000000
Answer: d
Explanation: Since the ASCII value of a is 97, the same is assigned to the float variable and printed.
Output:
$ cc pgm8.c
$ a.out
97.000000

 

32. Which of the data types has the size that is variable?
a) int
b) struct
c) float
d) double
Answer: b
Explanation: Since the size of the structure depends on its fields, it has a variable size.

 

 

33. What will be the output of the following C code?

 

#include
int main()
{
enum {ORANGE = 5, MANGO, BANANA = 4, PEACH};
printf(“PEACH = %d\n”, PEACH);
}
a) PEACH = 3
b) PEACH = 4
c) PEACH = 5
d) PEACH = 6
Answer: c
Explanation: In enum, the value of constant is defined to the recent assignment from left.
Output:
$ cc pgm1.c
$ a.out
PEACH = 5

 

34. What will be the output of the following C code?

 

#include
int main()
{
printf(“C programming %s”, “Class by\n%s Fatskills”, “VIVA”);
}
a)

C programming Class by
VIVA Fatskills
b) C programming Class by\n%s Fatskills
c)

C programming Class by
%s Fatskills

d) Compilation error
Answer: c
Explanation: This program has only one %s within first double quotes, so it does not read the string “WOW”.
The %s along with the Fatskills is not read as a format modifier while new line character prints the new line.
Output:
$ cc pgm2.c
$ a.out
C programming Class by
%s Fatskills

 

35. In the following code snippet, character pointer str holds a reference to the string ___________

 

 

char *str = “Sanfoundry.com\0” “training classes”;
a) Fatskills.com
b) Fatskills.com\0training classes
c) Fatskills.comtraining classes
d) Invalid declaration
Answer: b
Explanation: ‘\0’ is accepted as a char in the string. Even though strlen will give length of string “Sanfoundry.com”, in memory str is pointing to entire string including training classes.

 

 

36. What will be the output of the following C code?

 

#include
#define a 10
int main()
{
const int a = 5;
printf(“a = %d\n”, a);
}
a) a = 5
b) a = 10
c) Compilation error
d) Runtime error
Answer: c
Explanation: The #define substitutes a with 10 without leaving any identifier, which results in Compilation error.
Output:
$ cc pgm3.c
pgm3.c: In function ‘main’:
pgm3.c:5: error: expected identifier or ‘(’ before numeric constant

 

37. What will be the output of the following C code?

 

#include
int main()
{
int var = 010;
printf(“%d”, var);
}
a) 2
b) 8
c) 9
d) 10
Answer: b
Explanation: 010 is octal representation of 8.
Output:
$ cc pgm4.c
$ a.out
8

 

38. What will be the output of the following C function?

 

#include
enum birds {SPARROW, PEACOCK, PARROT};
enum animals {TIGER = 8, LION, RABBIT, ZEBRA};
int main()
{
enum birds m = TIGER;
int k;
k = m;
printf(“%d\n”, k);
return 0;
}
a) 0
b) Compile time error
c) 1
d) 8
Answer: d
Explanation: m is an integer constant, hence it is compatible.
Output:
$ cc pgm5.c
$ a.out
8

 

39. What will be the output of the following C code?

 

#include
#define MAX 2
enum bird {SPARROW = MAX + 1, PARROT = SPARROW + MAX};
int main()
{
enum bird b = PARROT;
printf(“%d\n”, b);
return 0;
}
a) Compilation error
b) 5
c) Undefined value
d) 2
Answer: b
Explanation: MAX value is 2 and hence PARROT will have value 3 + 2.
Output:
$ cc pgm6.c
$ a.out
5

 

40. What will be the output of the following C code?

 

#include
#include
int main()
{
char *str = “x”;
char c = ‘x’;
char ary[1];
ary[0] = c;
printf(“%d %d”, strlen(str), strlen(ary));
return 0;
}
a) 1 1
b) 2 1
c) 2 2
d) 1 (undefined value)
Answer: d
Explanation: str is null terminated, but ary is not null terminated.
Output:
$ cc pgm7.c
$ a.out
1 5

 

41. enum types are processed by _________
a) Compiler
b) Preprocessor
c) Linker
d) Assembler
Answer: a
Explanation: None.

 

 

42. What will be the output of the following C code?

 

#include
int main()
{
const int p;
p = 4;
printf(“p is %d”, p);
return 0;
}
a) p is 4
b) Compile time error
c) Run time error
d) p is followed by a garbage value
Answer: b
Explanation: Since the constant variable has to be declared and defined at the same time, not doing it results in an error.
Output:
$ cc pgm10.c
pgm10.c: In function ‘main’:
pgm10.c:5: error: assignment of read-only variable ‘p’

 

43. What will be the output of the following C code?

 

#include
void main()
{
int k = 4;
int *const p = &k;
int r = 3;
p = &r;
printf(“%d”, p);
}
a) Address of k
b) Address of r
c) Compile time error
d) Address of k + address of r
Answer: c
Explanation: Since the pointer p is declared to be constant, trying to assign it with a new value results in an error.
Output:
$ cc pgm11.c
pgm11.c: In function ‘main’:
pgm11.c:7: error: assignment of read-only variable ‘p’
pgm11.c:8: warning: format ‘%d’ expects type ‘int’, but argument 2 has type ‘int * const’

 

44. Which of the following statement is false?
a) Constant variables need not be defined as they are declared and can be defined later
b) Global constant variables are initialized to zero
c) const keyword is used to define constant values
d) You cannot reassign a value to a constant variable
Answer: a
Explanation: Since the constant variable has to be declared and defined at the same time, not doing it results in an error.

 

 

45. What will be the output of the following C code?

 

#include
void main()
{
int const k = 5;
k++;
printf(“k is %d”, k);
}
a) k is 6
b) Error due to const succeeding int
c) Error, because a constant variable can be changed only twice
d) Error, because a constant variable cannot be changed
Answer: d
Explanation: Constant variable has to be declared and defined at the same time. Trying to change it results in an error.
Output:
$ cc pgm12.c
pgm12.c: In function ‘main’:
pgm12.c:5: error: increment of read-only variable ‘k’

 

 

 

 

Part 2: Operators & Preceedence

1. What will be the output of the following C function?

 

#include
int main()
{
reverse(1);
}
void reverse(int i)
{
if (i > 5)
exit(0);
printf(“%d\n”, i);
return reverse(i++);
}
a) 1 2 3 4 5
b) 1 2 3 4
c) Compile time error
d) Stack overflow
Answer: d
Explanation: None.

 

2. What will be the output of the following C function?

 

#include
void reverse(int i);
int main()
{
reverse(1);
}
void reverse(int i)
{
if (i > 5)
return ;
printf(“%d “, i);
return reverse((i++, i));
}
a) 1 2 3 4 5
b) Segmentation fault
c) Compilation error
d) Undefined behaviour
Answer: a
Explanation: None.

 

3. In expression i = g() + f(), first function called depends on __________
a) Compiler
b) Associativiy of () operator
c) Precedence of () and + operator
d) Left to write of the expression
Answer: a
Explanation: None.

 

 

4. What will be the final values of i and j in the following C code?

 

#include
int x = 0;
int main()
{
int i = (f() + g()) || g();
int j = g() || (f() + g());
}
int f()
{
if (x == 0)
return x + 1;
else
return x – 1;
}
int g()
{
return x++;
}
a) i value is 1 and j value is 1
b) i value is 0 and j value is 0
c) i value is 1 and j value is undefined
d) i and j value are undefined
Answer: d
Explanation: None.

 

5. What will be the final values of i and j in the following C code?

 

#include
int x = 0;
int main()
{
int i = (f() + g()) | g(); //bitwise or
int j = g() | (f() + g()); //bitwise or
}
int f()
{
if (x == 0)
return x + 1;
else
return x – 1;
}
int g()
{
return x++;
}
a) i value is 1 and j value is 1
b) i value is 0 and j value is 0
c) i value is 1 and j value is undefined
d) i and j value are undefined
Answer: c
Explanation: None.

 

6. What will be the output of the following C code?

 

#include
int main()
{
int x = 2, y = 0;
int z = y && (y |= 10);
printf(“%d\n”, z);
return 0;
}
a) 1
b) 0
c) Undefined behaviour due to order of evaluation
d) 2
Answer: b
Explanation: None.

 

7. What will be the output of the following C code?

 

#include
int main()
{
int x = 2, y = 0;
int z = (y++) ? 2 : y == 1 && x;
printf(“%d\n”, z);
return 0;
}
a) 0
b) 1
c) 2
d) Undefined behaviour
Answer: b
Explanation: None.

 

8. What will be the output of the following C code?

 

#include
int main()
{
int x = 2, y = 0;
int z;
z = (y++, y);
printf(“%d\n”, z);
return 0;
}
a) 0
b) 1
c) Undefined behaviour
d) Compilation error
Answer: b
Explanation: None.

 

9. What will be the output of the following C code?

 

#include
int main()
{
int x = 2, y = 0, l;
int z;
z = y = 1, l = x && y;
printf(“%d\n”, l);
return 0;
}
a) 0
b) 1
c) Undefined behaviour due to order of evaluation can be different
d) Compilation error
Answer: b
Explanation: None.

 

10. What will be the output of the following C code?

 

#include
int main()
{
int y = 2;
int z = y +(y = 10);
printf(“%d\n”, z);
}
a) 12
b) 20
c) 4
d) Either 12 or 20
Answer: b
Explanation: None.

 

11. What will be the output of the following C code?

 

#include
int main()
{
int x = 2, y = 2;
float f = y + x /= x / y;
printf(“%d %f\n”, x, f);
return 0;
}
a) 2 4.000000
b) Compile time error
c) 2 3.500000
d) Undefined behaviour
Answer: b
Explanation: None.

 

12. What will be the output of the following C code?

 

#include
int main()
{
int x = 1, y = 2;
if (x && y == 1)
printf(“true\n”);
else
printf(“false\n”);
}
a) true
b) false
c) compile time error
d) undefined behaviour
Answer: b
Explanation: None.

 

13. What will be the output of the following C code?

 

#include
int main()
{
int x = 1, y = 2;
int z = x & y == 2;
printf(“%d\n”, z);
}
a) 0
b) 1
c) Compile time error
d) Undefined behaviour
Answer: b
Explanation: None.

 

14. What will be the output of the following C code?

 

#include
int main()
{
int x = 3, y = 2;
int z = x /= y %= 2;
printf(“%d\n”, z);
}
a) 1
b) Compile time error
c) Floating point exception
d) Segmentation fault
Answer: c
Explanation: None.

 

15. What will be the output of the following C code?

 

#include
int main()
{
int x = 3, y = 2;
int z = x << 1 > 5;
printf(“%d\n”, z);
}
a) 1
b) 0
c) 3
d) Compile time error
Answer: a
Explanation: None.

 

16. What will be the output of the following C code?

 

#include
int main()
{
int x = 3; //, y = 2;
const int *p = &x;
*p++;
printf(“%d\n”, *p);
}
a) Increment of read-only location compile error
b) 4
c) Some garbage value
d) Undefined behaviour
Answer: c
Explanation: None.

 

17. What will be the output of the following C code?

 

#include
int main()
{
int x = 2, y = 2;
int z = x ^ y & 1;
printf(“%d\n”, z);
}
a) 1
b) 2
c) 0
d) 1 or 2
Answer: b
Explanation: None.

 

18. What will be the output of the following C code?

 

#include
int main()
{
int x = 2, y = 0;
int z = x && y = 1;
printf(“%d\n”, z);
}
a) 0
b) 1
c) Compile time error
d) 2
Answer: c
Explanation: None.

 

19. What will be the output of the following C code?

 

#include
int main()
{
int x = 0, y = 2;
if (!x && y)
printf(“true\n”);
else
printf(“false\n”);
}
a) True
b) False
c) Compile time error
d) Undefined behaviour
Answer: a
Explanation: None.

 

20. What will be the output of the following C code?

 

#include
int main()
{
int x = 0, y = 2;
int z = ~x & y;
printf(“%d\n”, z);
}
a) -1
b) 2
c) 0
d) Compile time error
Answer: b
Explanation: None.

 

21. What will be the output of the following C code?

 

#include
int main()
{
int i = -3;
int k = i % 2;
printf(“%d\n”, k);
}
a) Compile time error
b) -1
c) 1
d) Implementation defined
Answer: b
Explanation: None.

 

22. What will be the output of the following C code?

 

#include
int main()
{
int i = 3;
int l = i / -2;
int k = i % -2;
printf(“%d %d\n”, l, k);
return 0;
}
a) Compile time error
b) -1 1
c) 1 -1
d) Implementation defined
Answer: b
Explanation: None.

 

23. What will be the output of the following C code?

 

#include
int main()
{
int i = 5;
i = i / 3;
printf(“%d\n”, i);
return 0;
}
a) Implementation defined
b) 1
c) 3
d) Compile time error
Answer: b
Explanation: None.

 

24. What will be the output of the following C code?

 

#include
int main()
{
int i = -5;
i = i / 3;
printf(“%d\n”, i);
return 0;
}
a) Implementation defined
b) -1
c) -3
d) Compile time error
Answer: b
Explanation: None.

 

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

 

#include
void main()
{
int x = 5 * 9 / 3 + 9;
}
a) 3.75
b) Depends on compiler
c) 24
d) 3
Answer: c
Explanation: None.

 

26. What will be the output of the following C code?

 

#include
void main()
{
int x = 5.3 % 2;
printf(“Value of x is %d”, x);
}
a) Value of x is 2.3
b) Value of x is 1
c) Value of x is 0.3
d) Compile time error
Answer: d
Explanation: None.

 

27. What will be the output of the following C code?

 

#include
void main()
{
int y = 3;
int x = 5 % 2 * 3 / 2;
printf(“Value of x is %d”, x);
}
a) Value of x is 1
b) Value of x is 2
c) Value of x is 3
d) Compile time error
Answer: a
Explanation: None.

 

28. What will be the output of the following C code?

 

#include
void main()
{
int a = 3;
int b = ++a + a++ + –a;
printf(“Value of b is %d”, b);
}
a) Value of x is 12
b) Value of x is 13
c) Value of x is 10
d) Undefined behaviour
Answer: d
Explanation: None.

 

29. What is the precedence of arithmetic operators (from highest to lowest)?
a) %, *, /, +, –
b) %, +, /, *, –
c) +, -, %, *, /
d) %, +, -, *, /
Answer: a
Explanation: None.

 

 

30. Which of the following is not an arithmetic operation?
a) a * = 10;
b) a / = 10;
c) a ! = 10;
d) a % = 10;
Answer: c
Explanation: None.

 

 

31. Which of the following data type will throw an error on modulus operation(%)?
a) char
b) short
c) int
d) float
Answer: d
Explanation: None.

 

 

32. Which among the following are the fundamental arithmetic operators, i.e, performing the desired operation can be done using that operator only?
a) +, –
b) +, -, %
c) +, -, *, /
d) +, -, *, /, %
Answer: a
Explanation: None.

 

 

33. What will be the output of the following C code?

 

#include
int main()
{
int a = 10;
double b = 5.6;
int c;
c = a + b;
printf(“%d”, c);
}
a) 15
b) 16
c) 15.6
d) 10
Answer: a
Explanation: None.

 

34. What will be the output of the following C code?

 

#include
int main()
{
int a = 10, b = 5, c = 5;
int d;
d = a == (b + c);
printf(“%d”, d);
}
a) Syntax error
b) 1
c) 10
d) 5
Answer: b
Explanation: None.

 

35. What will be the output of the following C code?

 

#include
void main()
{
int x = 1, y = 0, z = 5;
int a = x && y || z++;
printf(“%d”, z);
}
a) 6
b) 5
c) 0
d) Varies
Answer: a
Explanation: None.

 

36. What will be the output of the following C code?

 

#include
void main()
{
int x = 1, y = 0, z = 5;
int a = x && y && z++;
printf(“%d”, z);
}
a) 6
b) 5
c) 0
d) Varies
Answer: b
Explanation: None.

 

37. What will be the output of the following C code?

 

#include
int main()
{
int x = 1, y = 0, z = 3;
x > y ? printf(“%d”, z) : return z;
}
a) 3
b) 1
c) Compile time error
d) Run time error
Answer: c
Explanation: None.

 

38. What will be the output of the following C code?

 

#include
void main()
{
int x = 1, z = 3;
int y = x << 3;
printf(” %d\n”, y);
}
a) -2147483648
b) -1
c) Run time error
d) 8
Answer: d
Explanation: None.

 

39. What will be the output of the following C code?

 

#include
void main()
{
int x = 0, y = 2, z = 3;
int a = x & y | z;
printf(“%d”, a);
}
a) 3
b) 0
c) 2
d) Run time error
Answer: a
Explanation: None.

 

40. What will be the final value of j in the following C code?

 

#include
int main()
{
int i = 0, j = 0;
if (i && (j = i + 10))
//do something
;
}
a) 0
b) 10
c) Depends on the compiler
d) Depends on language standard
Answer: a
Explanation: None.

 

41. What will be the final value of j in the following C code?

 

#include
int main()
{
int i = 10, j = 0;
if (i || (j = i + 10))
//do something
;
}
a) 0
b) 20
c) Compile time error
d) Depends on language standard
Answer: a
Explanation: None.

 

42. What will be the output of the following C code?

 

#include
int main()
{
int i = 1;
if (i++ && (i == 1))
printf(“Yes\n”);
else
printf(“No\n”);
}
a) Yes
b) No
c) Depends on the compiler
d) Depends on the standard
Answer: b
Explanation: None.

 

43. Are logical operator sequence points?
a) True
b) False
c) Depends on the compiler
d) Depends on the standard
Answer: a
Explanation: None.

 

 

44. Do logical operators in the C language are evaluated with the short circuit?
a) True
b) False
c) Depends on the compiler
d) Depends on the standard
Answer: a
Explanation: None.

 

 

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
Answer: b
Explanation: None.

 

 

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

 

#include
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
Answer: b
Explanation: None.

 

47. What will be the output of the following C code?

 

#include
int main()
{
int a = 10, b = 5, c = 3;
b != !a;
c = !!a;
printf(“%d\t%d”, b, c);
}
a) 5 1
b) 0 3
c) 5 3
d) 1 1
Answer: a
Explanation: None.

 

48. Which among the following is NOT a logical or relational operator?
a) !=
b) ==
c) ||
d) =
Answer: d
Explanation: None.

 

 

49. What will be the output of the following C code?

 

#include
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
Answer: d
Explanation: This is a sequence point problem and hence the result will be implementation dependent.

 

50. Relational operators cannot be used on ____________
a) structure
b) long
c) strings
d) float
Answer: a
Explanation: None.

 

 

51. What is the difference between the following 2 codes?

 

#include //Program 1
int main()
{
int d, a = 1, b = 2;
d = a++ + ++b;
printf(“%d %d %d”, d, a, b);
}
#include //Program 2
int main()
{
int d, a = 1, b = 2;
d = a++ +++b;
printf(“%d %d %d”, d, a, b);
}
a) No difference as space doesn’t make any difference, values of a, b, d are same in both the case
b) Space does make a difference, values of a, b, d are different
c) Program 1 has syntax error, program 2 is not
d) Program 2 has syntax error, program 1 is not
Answer: d
Explanation: None.

 

52. What will be the output of the following C code?

 

#include
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
Answer: b
Explanation: None.

 

53. What will be the output of the following C code?

 

#include
int main()
{
int a = 1, b = 1, d = 1;
printf(“%d, %d, %d”, ++a + ++a+a++, a++ + ++b, ++d + d++ + a++);
}
a) 15, 4, 5
b) 9, 6, 9
c) 9, 3, 5
d) Undefined (Compiler Dependent)
Answer: d
Explanation: None.

 

54. For which of the following, “PI++;” code will fail?
a) #define PI 3.14
b) char *PI = “A”;
c) float PI = 3.14;
d) none of the Mentioned
Answer: a
Explanation: None.

 

 

55. What will be the output of the following C code?

 

#include
int main()
{
int a = 10, b = 10;
if (a = 5)
b–;
printf(“%d, %d”, a, b–);
}
a) a = 10, b = 9
b) a = 10, b = 8
c) a = 5, b = 9
d) a = 5, b = 8
Answer: c
Explanation: None.

 

56. What will be the output of the following C code?

 

#include
int main()
{
int i = 0;
int j = i++ + i;
printf(“%d\n”, j);
}
a) 0
b) 1
c) 2
d) Compile time error
Answer: b
Explanation: None.

 

57. What will be the output of the following C code?

 

#include
int main()
{
int i = 2;
int j = ++i + i;
printf(“%d\n”, j);
}
a) 6
b) 5
c) 4
d) Compile time error
Answer: a
Explanation: None.

 

58. What will be the output of the following C code?

 

#include
int main()
{
int i = 2;
int i = i++ + i;
printf(“%d\n”, i);
}
a) = operator is not a sequence point
b) ++ operator may return value with or without side effects
c) it can be evaluated as (i++)+i or i+(++i)
d) = operator is a sequence point
Answer: a
Explanation: None.

 

59. What will be the output of the following C code?

 

#include
int main()
{
int i = 0;
int x = i++, y = ++i;
printf(“%d % d\n”, x, y);
return 0;
}
a) 0, 2
b) 0, 1
c) 1, 2
d) Undefined
Answer: a
Explanation: None.

 

60. What will be the output of the following C code?

 

#include
int main()
{
int i = 10;
int *p = &i;
printf(“%d\n”, *p++);
}
a) 10
b) 11
c) Garbage value
d) Address of i
Answer: a
Explanation: None.

 

61. What will be the output of the following C code?

 

#include
void main()
{
int x = 97;
int y = sizeof(x++);
printf(“X is %d”, x);
}
a) X is 97
b) X is 98
c) X is 99
d) Run time error
Answer: a
Explanation: None.

 

62. What will be the output of the following C code?

 

#include
void main()
{
int x = 4, y, z;
y = –x;
z = x–;
printf(“%d%d%d”, x, y, z);
}
a) 3 2 3
b) 2 3 3
c) 3 2 2
d) 2 3 4
Answer: b
Explanation: None.

 

63. What will be the output of the following C code?

 

#include
void main()
{
int x = 4;
int *p = &x;
int *k = p++;
int r = p – k;
printf(“%d”, r);
}
a) 4
b) 8
c) 1
d) Run time error
Answer: c
Explanation: None.

 

64. What will be the output of the following C code?

 

#include
void main()
{
int a = 5, b = -7, c = 0, d;
d = ++a && ++b || ++c;
printf(“\n%d%d%d%d”, a, b, c, d);
}
a) 6 -6 0 0
b) 6 -5 0 1
c) -6 -6 0 1
d) 6 -6 0 1
Answer: d
Explanation: None.

 

64. What will be the output of the following C code?

 

#include
void main()
{
int a = -5;
int k = (a++, ++a);
printf(“%d\n”, k);
}
a) -4
b) -5
c) 4
d) -3
Answer: d
Explanation: None.

 

65. What will be the output of the following C code?

 

#include
int main()
{
int c = 2 ^ 3;
printf(“%d\n”, c);
}
a) 1
b) 8
c) 9
d) 0
Answer: a
Explanation: None.

 

66. What will be the output of the following C code?

 

#include
int main()
{
unsigned int a = 10;
a = ~a;
printf(“%d\n”, a);
}
a) -9
b) -10
c) -11
d) 10
Answer: c
Explanation: None.

 

67. What will be the output of the following C code?

 

#include
int main()
{
if (7 & 8)
printf(“Honesty”);
if ((~7 & 0x000f) == 8)
printf(“is the best policy\n”);
}
a) Honesty is the best policy
b) Honesty
c) is the best policy
d) No output
Answer: c
Explanation: None.

 

68. What will be the output of the following C code?

 

#include
int main()
{
int a = 2;
if (a >> 1)
printf(“%d\n”, a);
}
a) 0
b) 1
c) 2
d) No Output
Answer: c
Explanation: None.

 

69. Comment on the output of the following C code.

 

#include
int main()
{
int i, n, a = 4;
scanf(“%d”, &n);
for (i = 0; i < n; i++)
a = a * 2;
}
a) Logical Shift left
b) No output
c) Arithmetic Shift right
d) Bitwise exclusive OR
Answer: b
Explanation: None.

 

70. What will be the output of the following C code?

 

#include
void main()
{
int x = 97;
int y = sizeof(x++);
printf(“x is %d”, x);
}
a) x is 97
b) x is 98
c) x is 99
d) Run time error
Answer: a
Explanation: None.

 

71. What will be the output of the following C code?

 

#include
void main()
{
int x = 4, y, z;
y = –x;
z = x–;
printf(“%d%d%d”, x, y, z);
}
a) 3 2 3
b) 2 2 3
c) 3 2 2
d) 2 3 3
Answer: d
Explanation: None.

 

72. What will be the output of the following C code?

 

#include
void main()
{
int x = 4;
int *p = &x;
int *k = p++;
int r = p – k;
printf(“%d”, r);
}
a) 4
b) 8
c) 1
d) Run time error
Answer: c
Explanation: None.

 

73. What will be the output of the following C code?

 

#include
void main()
{
int a = 5, b = -7, c = 0, d;
d = ++a && ++b || ++c;
printf(“\n%d%d%d%d”, a, b, c, d);
}
a) 6 -6 0 0
b) 6 -5 0 1
c) -6 -6 0 1
d) 6 -6 0 1
Answer: d
Explanation: None.

 

74. What will be the output of the following C code?

 

#include
void main()
{
int a = -5;
int k = (a++, ++a);
printf(“%d\n”, k);
}
a) -3
b) -5
c) 4
d) Undefined
Answer: a
Explanation: None.

 

75. What will be the output of the following C code?

 

#include
int main()
{
int x = 2;
x = x << 1;
printf(“%d\n”, x);
}
a) 4
b) 1
c) Depends on the compiler
d) Depends on the endianness of the machine
Answer: a
Explanation: None.

 

76. What will be the output of the following C code?

 

#include
int main()
{
int x = -2;
x = x >> 1;
printf(“%d\n”, x);
}
a) 1
b) -1
c) 2 31 – 1 considering int to be 4 bytes
d) Either -1 or 1
Answer: b
Explanation: None.

 

77. What will be the output of the following C code?

 

#include
int main()
{
if (~0 == 1)
printf(“yes\n”);
else
printf(“no\n”);
}
a) yes
b) no
c) compile time error
d) undefined
Answer: b
Explanation: None.

 

78. What will be the output of the following C code?

 

#include
int main()
{
int x = -2;
if (!0 == 1)
printf(“yes\n”);
else
printf(“no\n”);
}
a) yes
b) no
c) run time error
d) undefined
Answer: a
Explanation: None.

 

79. What will be the output of the following C code?

 

#include
int main()
{
int y = 0;
if (1 |(y = 1))
printf(“y is %d\n”, y);
else
printf(“%d\n”, y);

 

}
a) y is 1
b) 1

c) run time error
d) undefined
Answer: a
Explanation: None.

 

 

80. What will be the output of the following C code?

 

#include
int main()
{
int y = 1;
if (y & (y = 2))
printf(“true %d\n”, y);
else
printf(“false %d\n”, y);

 

}
a) true 2
b) false 2
c) either true 2 or false 2
d) true 1
Answer: a
Explanation: None.

 

 

81. What will be the output of the following C code?

 

#include
void main()
{
int k = 8;
int m = 7;
k < m ? k++ : m = k;
printf(“%d”, k);
}
a) 7
b) 8
c) Compile time error
d) Run time error
Answer: c
Explanation: None.

 

82. What will be the output of the following C code?

 

#include
void main()
{
int k = 8;
int m = 7;
k < m ? k = k + 1 : m = m + 1;
printf(“%d”, k);
}
a) Compile time error
b) 9
c) 8
d) Run time error
Answer: a
Explanation: None.

 

83. What will be the final values of a and c in the following C statement? (Initial values: a = 2, c = 1)

 

c = (c) ? a = 0 : 2;
a) a = 0, c = 0;
b) a = 2, c = 2;
c) a = 2, c = 2;
d) a = 1, c = 2;
Answer: a
Explanation: None.

 

84. What will be the data type of the following expression? (Initial data type: a = int, var1 = double, var2 = float)

 

expression (a < 50)? var1 : var2;
a) int
b) float
c) double
d) Cannot be determined
Answer: c
Explanation: None.

 

85. Which expression has to be present in the following?
exp1 ? exp2 : exp3;
a) exp1
b) exp2
c) exp3
d) all of the mentioned
Answer: d
Explanation: None.

 

 

86. What will be the final value of c in the following C code snippet? (Initial values: a = 1, b = 2, c = 1)

 

c += (-c) ? a : b;
a) Syntax Error
b) c = 1
c) c = 2
d) c = 3
Answer: c
Explanation: None.

 

87. The following C code can be rewritten as _______

 

c = (n) ? a : b;
a)

if (!n)c = b;
else c = a;
b)

if (n <;= 0)c = b;
else c = a;
c)

if (n > 0)c = a;
else c = b;
d) All of the mentioned
Answer: a
Explanation: None.

 

 

 

 

Part 3: Control Structures, Branching & Looping

1. What will be the output of the following C code?

 

#include
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
Answer: a
Explanation: None.

 

2. What will be the output of the following C code?

 

#include
int x;
void main()
{
if (x)
printf(“hi”);
else
printf(“how are u”);
}
a) hi
b) how are you
c) compile time error
d) error
Answer: b
Explanation: None.

 

3. What will be the output of the following C code?

 

#include
void main()
{
int x = 5;
if (true);
printf(“hello”);
}
a) It will display hello
b) It will throw an error
c) Nothing will be displayed
d) Compiler dependent
Answer: b
Explanation: None.

 

4. What will be the output of the following C code?

 

#include
void main()
{
int x = 0;
if (x == 0)
printf(“hi”);
else
printf(“how are u”);
printf(“hello”);
}
a) hi
b) how are you
c) hello
d) hihello
Answer: d
Explanation: None.

 

5. What will be the output of the following C code?

 

#include
void main()
{
int x = 5;
if (x < 1);
printf(“Hello”);

 

}
a) Nothing
b) Run time error
c) Hello
d) Varies
Answer: c
Explanation: None.

 

 

6. What will be the output of the following C code? (Assuming that we have entered the value 1 in the standard input)

 

#include
void main()
{
double ch;
printf(“enter a value between 1 to 2:”);
scanf(“%lf”, &ch);
switch (ch)
{
case 1:
printf(“1”);
break;
case 2:
printf(“2”);
break;
}
}
a) Compile time error
b) 1
c) 2
d) Varies
Answer: a
Explanation: None.

 

7. What will be the output of the following C code? (Assuming that we have entered the value 1 in the standard input)

 

#include
void main()
{
char *ch;
printf(“enter a value between 1 to 3:”);
scanf(“%s”, ch);
switch (ch)
{
case “1”:
printf(“1”);
break;
case “2”:
printf(“2”);
break;
}
}
a) 1
b) 2
c) Compile time error
d) No Compile time error
Answer: c
Explanation: None.

 

8. What will be the output of the following C code? (Assuming that we have entered the value 1 in the standard input)

 

#include
void main()
{
int ch;
printf(“enter a value between 1 to 2:”);
scanf(“%d”, &ch);
switch (ch)
{
case 1:
printf(“1\n”);
default:
printf(“2\n”);
}
}
a) 1
b) 2
c) 1 2
d) Run time error
Answer: c
Explanation: None.

 

9. What will be the output of the following C code? (Assuming that we have entered the value 2 in the standard input)

 

#include
void main()
{
int ch;
printf(“enter a value between 1 to 2:”);
scanf(“%d”, &ch);
switch (ch)
{
case 1:
printf(“1\n”);
break;
printf(“Hi”);
default:
printf(“2\n”);
}
}
a) 1
b) Hi 2
c) Run time error
d) 2
Answer: d
Explanation: None.

 

10. What will be the output of the following C code? (Assuming that we have entered the value 1 in the standard input)

 

#include
void main()
{
int ch;
printf(“enter a value between 1 to 2:”);
scanf(“%d”, &ch);
switch (ch, ch + 1)
{
case 1:
printf(“1\n”);
break;
case 2:
printf(“2”);
break;
}
}
a) 1
b) 2
c) 3
d) Run time error
Answer: b
Explanation: None.

 

11. What will be the output of the following C code?

 

#include
int main()
{
int x = 1;
if (x > 0)
printf(“inside if\n”);
else if (x > 0)
printf(“inside elseif\n”);
}
a) inside if
b) inside elseif
c)

inside if
inside elseif
d) compile time error
Answer: a
Explanation: None.

 

12. What will be the output of the following C code?

 

#include
int main()
{
int x = 0;
if (x++)
printf(“true\n”);
else if (x == 1)
printf(“false\n”);
}
a) true
b) false
c) compile time error
d) undefined behaviour
Answer: b
Explanation: None.

 

13. What will be the output of the following C code?

 

#include
int main()
{
int x = 0;
if (x == 1)
if (x == 0)
printf(“inside if\n”);
else
printf(“inside else if\n”);
else
printf(“inside else\n”);
}
a) inside if
b) inside else if
c) inside else
d) compile time error
Answer: c
Explanation: None.

 

14. What will be the output of the following C code?

 

#include
int main()
{
int x = 0;
if (x == 0)
printf(“true, “);
else if (x = 10)
printf(“false, “);
printf(“%d\n”, x);
}
a) false, 0
b) true, 0
c) true, 10
d) compile time error
Answer: b
Explanation: None.

 

15. What will be the output of the following C code?

 

#include
int main()
{
int x = 0;
if (x == 1)
if (x >= 0)
printf(“true\n”);
else
printf(“false\n”);
}
a) true
b) false
c) Depends on the compiler
d) No print statement
Answer: d
Explanation: None.

 

16. The C statement “”if (a == 1 || b == 2) {}”” can be re-written as ___________
a)

 

if (a == 1)
if (b == 2){}
b)

if (a == 1){}
if (b == 2){}
c)

if (a == 1){}
else if (b == 2){}
d) none of the mentioned
Answer: d
Explanation: None.

 

17. Which of the following is an invalid if-else statement?
a) if (if (a == 1)){}
b) if (func1 (a)){}
c) if (a){}
d) if ((char) a){}
Answer: a
Explanation: None.

 

 

18. What will be the output of the following C code?

 

#include
int main()
{
int a = 1;
if (a–)
printf(“True”);
if (a++)
printf(“False”);
}
a) True
b) False
c) True False
d) No Output
Answer: a
Explanation: None.

 

19. What will be the output of the following C code?

 

#include
int main()
{
int a = 1;
if (a)
printf(“All is Well “);
printf(“I am Well\n”);
else
printf(“I am not a River\n”);
}
a) Output will be All is Well I am Well
b) Output will be I am Well I am not a River
c) Output will be I am Well
d) Compile time errors during compilation
Answer: d
Explanation: None.

 

20. What will be the output of the following C code?

 

#include
int main()
{
if (printf(“%d”, printf(“)))
printf(“We are Happy”);
else if (printf(“1”))
printf(“We are Sad”);
}
a) 0We are Happy
b) 1We are Happy
c) 1We are Sad
d) compile time error
Answer: d
Explanation: None.

 

21. What will be the output of the following C code? (Assuming that we have entered the value 1 in the standard input)

 

#include
void main()
{
double ch;
printf(“enter a value between 1 to 2:”);
scanf(“%lf”, &ch);
switch (ch)
{
case 1:
printf(“1”);
break;
case 2:
printf(“2”);
break;
}
}
a) Compile time error
b) 1
c) 2
d) Varies
Answer: a
Explanation: None.

 

22. What will be the output of the following C code? (Assuming that we have entered the value 1 in the standard input)

 

#include
void main()
{
char *ch;
printf(“enter a value between 1 to 3:”);
scanf(“%s”, ch);
switch (ch)
{
case “1”:
printf(“1”);
break;
case “2”:
printf(“2”);
break;
}
}
a) 1
b) Compile time error
c) 2
d) Run time error
Answer: b
Explanation: None.

 

23. What will be the output of the following C code? (Assuming that we have entered the value 1 in the standard input)

 

#include
void main()
{
int ch;
printf(“enter a value between 1 to 2:”);
scanf(“%d”, &ch);
switch (ch)
{
case 1:
printf(“1\n”);
default:
printf(“2\n”);
}
}
a) 1
b) 2
c) 1 2
d) Run time error
Answer: c
Explanation: None.

 

24. What will be the output of the following C code? (Assuming that we have entered the value 2 in the standard input)

 

#include
void main()
{
int ch;
printf(“enter a value between 1 to 2:”);
scanf(“%d”, &ch);
switch (ch)
{
case 1:
printf(“1\n”);
break;
printf(“hi”);
default:
printf(“2\n”);
}
}
a) 1
b) hi 2
c) Run time error
d) 2
Answer: d
Explanation: None.

 

25. What will be the output of the following C code? (Assuming that we have entered the value 1 in the standard input)

 

#include
void main()
{
int ch;
printf(“enter a value between 1 to 2:”);
scanf(“%d”, &ch);
switch (ch, ch + 1)
{
case 1:
printf(“1\n”);
break;
case 2:
printf(“2”);
break;
}
}
a) 1
b) 2
c) 3
d) Run time error
Answer: b
Explanation: None.

 

26. What will be the output of the following C code?

 

#include
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) Compile time error
d) yes no
Answer: c
Explanation: None.

 

27. What will be the output of the following C code?

 

#include
int main()
{
int x = 97;
switch (x)
{
case ‘a’:
printf(“yes “);
break;
case 97:
printf(“no\n”);
break;
}
}
a) yes
b) yes no
c) Duplicate case value error
d) Character case value error
Answer: c
Explanation: None.

 

28. What will be the output of the following C code?

 

#include
int main()
{
float f = 1;
switch (f)
{
case 1.0:
printf(“yes\n”);
break;
default:
printf(“default\n”);
}
}
a) yes
b) yes default
c) Undefined behaviour
d) Compile time error
Answer: d
Explanation: None.

 

29. What will be the output of the following C code?

 

#include
const int a = 1, b = 2;
int main()
{
int x = 1;
switch (x)
{
case a:
printf(“yes “);
case b:
printf(“no\n”);
break;
}
}
a) yes no
b) yes
c) no
d) Compile time error
Answer: d
Explanation: None.

 

30. What will be the output of the following C code?

 

#include
#define max(a) a
int main()
{
int x = 1;
switch (x)
{
case max(2):
printf(“yes\n”);
case max(1):
printf(“no\n”);
break;
}
}
a) yes no
b) yes
c) no
d) Compile time error
Answer: c
Explanation: None.

 

31. What will be the output of the following C code?

 

#include
int main()
{
switch (printf(“Do”))
{
case 1:
printf(“First\n”);
break;
case 2:
printf(“Second\n”);
break;
default:
printf(“Default\n”);
break;
}
}
a) Do
b) DoFirst
c) DoSecond
d) DoDefault
Answer: c
Explanation: None.

 

32. Comment on the output of the following C code.

 

#include
int main()
{
int a = 1;
switch (a)
case 1:
printf(“%d”, a);
case 2:
printf(“%d”, a);
case 3:
printf(“%d”, a);
default:
printf(“%d”, a);
}
a) No error, output is 1111
b) No error, output is 1
c) Compile time error, no break statements
d) Compile time error, case label outside switch statement
Answer: d
Explanation: None.

 

33. Which datatype can accept the switch statement?
a) int
b) char
c) long
d) all of the mentioned
Answer: d
Explanation: None.

 

 

34. What will be the output of the following C code?

 

#include
int main()
{
int a = 1;
switch (a)
{
case a:
printf(“Case A “);
default:
printf(“Default”);
}
}
a) Output: Case A
b) Output: Default
c) Output: Case A Default
d) Compile time error
Answer: d
Explanation: None.

 

35. What will be the output of the following C code?

 

#include
switch (ch)
{
case ‘a’:
case ‘A’:
printf(“true”);
}
a) if (ch == ‘a’ && ch == ‘A’) printf(“true”);
b)

if (ch == ‘a’)
if (ch == ‘a’) printf(“true”);
c) if (ch == ‘a’ || ch == ‘A’) printf(“true”);
d) none of the mentioned
Answer: c
Explanation: None.

 

36. The C code ‘for(;;)’ represents an infinite loop. It can be terminated by ___________
a) break
b) exit(0)
c) abort()
d) terminate
Answer: a
Explanation: None.

 

 

37. What will be the correct syntax for running two variable for loop simultaneously?
a)

 

 

for (i = 0; i < n; i++)
for (j = 0; j < n; j += 5)
b)

 

 

for (i = 0, j = 0; i < n, j < n; i++, j += 5)
c)

 

 

for (i = 0; i < n;i++){}
for (j = 0; j < n;j += 5){}
d) none of the mentioned
Answer: b
Explanation: None.

 

 

38. Which for loop has range of similar indexes of ‘i’ used in for (i = 0;i < n; i++)?
a) for (i = n; i>0; i–)
b) for (i = n; i >= 0; i–)
c) for (i = n-1; i>0; i–)
d) for (i = n-1; i>-1; i–)
Answer: d
Explanation: None.

 

 

39. Which of the following cannot be used as LHS of the expression in for (exp1;exp2; exp3)?
a) variable
b) function
c) typedef
d) macros
Answer: d
Explanation: None.

 

 

40. What will be the output of the following C code?

 

#include
int main()
{
short i;
for (i = 1; i >= 0; i++)
printf(“%d\n”, i);

 

}
a) The control won’t fall into the for loop
b) Numbers will be displayed until the signed limit of short and throw a runtime error
c) Numbers will be displayed until the signed limit of short and program will successfully terminate
d) This program will get into an infinite loop and keep printing numbers with no errors
Answer: c
Explanation: None.

 

 

41. What will be the output of the following C code?

 

#include
void main()
{
int k = 0;
for (k)
printf(“Hello”);
}
a) Compile time error
b) hello
c) Nothing
d) Varies
Answer: a
Explanation: None.

 

42. What will be the output of the following C code?

 

#include
void main()
{
int k = 0;
for (k < 3; k++)
printf(“Hello”);
}
a) Compile time error
b) Hello is printed thrice
c) Nothing
d) Varies
Answer: a
Explanation: None.

 

43. What will be the output of the following C code?

 

#include
void main()
{
double k = 0;
for (k = 0.0; k < 3.0; k++)
printf(“Hello”);
}
a) Run time error
b) Hello is printed thrice
c) Hello is printed twice
d) Hello is printed infinitely
Answer: b
Explanation: None.

 

44. What will be the output of the following C code?

 

#include
void main()
{
double k = 0;
for (k = 0.0; k < 3.0; k++);
printf(“%lf”, k);
}
a) 2.000000
b) 4.000000
c) 3.000000
d) Run time error
Answer: c
Explanation: None.

 

45. What will be the output of the following C code?

 

#include
void main()
{
int k;
for (k = -3; k < -5; k++)
printf(“Hello”);
}
a) Hello
b) Infinite hello
c) Run time error
d) Nothing
Answer: d
Explanation: None.

 

46. What will be the output of the following C code?

 

#include
int main()
{
int i = 0;
for (; ;



ADVERTISEMENT