JSPM'S Jayawantrao Sawant College of Engineeringhadpsar, Pune-33 Department of Information Technology Multiple Choice Questions Unit-1

Download as pdf or txt
Download as pdf or txt
You are on page 1of 30

JSPM's

Jayawantrao sawant College of EngineeringHadpsar, Pune-33


Department of Information Technology
Multiple Choice Questions

Unit-1

1. 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

2. Variable names beginning with underscore is not encouraged. Why?


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

3. All keywords in C are in


a) LowerCase letters
b) UpperCase letters
c) CamelCase letters
d) None
Answer:a

4. Variable name resolving (number of significant characters for uniqueness of variable) depends
on
a) Compiler and linker implementations
b) Assemblers and loaders implementations
c) C language
d) None
Answer:a

5. 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

6. 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

7. What is the output of this C code?


#include <stdio.h>
int main()
{
int c = 2 ^ 3;
printf("%d\n", c);
}

a) 1
b) 8
c) 9
d) 0
Answer: a

8. What is the output of this C code?

#include <stdio.h>
int main()
{
unsigned int a = 10;
a = ~a;
printf("%d\n", a);
}

a) -9
b) -10
c) -11
d) 10
Answer:c

9. What is the output of this C code?

#include <stdio.h>
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

10. What is the output of this C code?

#include <stdio.h>
int main()
{
int a = 2;
if (a >> 1)
printf("%d\n", a);
}

a) 0
b) 1
c) 2
d) No Output.
Answer:c

11. Comment on the output of this C code?

#include <stdio.h>
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

12. What is the output of this C code?

#include <stdio.h>
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

13. What is the output of this C code?

#include <stdio.h>
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

14. What is the output of this C code?

#include <stdio.h>
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

15. What is the output of this C code?

#include <stdio.h>
int main()
{
int x = 2, y = 0;
int z = (y++) ? y == 1 && x : 0;
printf("%d\n", z);
return 0;
}
a) 0
b) 1
c) Undefined behaviour
d) Compile time error
Answer:a

16. What is the output of this C code?

#include <stdio.h>
int main()
{
int x = 1;
int y = x == 1 ? getchar(): 2;
printf("%d\n", y);
}

a) Compile time error


b) Whatever character getchar function returns
c) Ascii value of character getchar function returns
d) 2
Answer:c

17. What is the output of this C code?

#include <stdio.h>
int main()
{
int x = 1;
short int i = 2;
float f = 3;
if (sizeof((x == 2) ? f : i) == sizeof(float))
printf("float\n");
else if (sizeof((x == 2) ? f : i) == sizeof(short int))
printf("short int\n");
}

a) float
b) short int
c) Undefined behaviour
d) Compile time error
Answer:a

18. What is the output of this C code?

#include <stdio.h>
int main()
{
int a = 2;
int b = 0;
int y = (b == 0) ? a :(a > b) ? (b = 1): a;
printf("%d\n", y);
}

a) Compile time error


b) 1
c) 2
d) Undefined behaviour
Answer:c

19. What is the output of this C code?

#include <stdio.h>
int main()
{
int y = 1, x = 0;
int l = (y++, x++) ? y : x;
printf("%d\n", l);
}

a) 1
b) 2
c) Compile time error
d) Undefined behaviour
Answer:a

19. Comment on the output of this C code?

#include <stdio.h>
void main()
{
int k = 8;
int m = 7;
int z = k < m ? k = m : m++;
printf("%d", z);
}

a) Run time error


b) 7
c) 8

d) Depends on compiler
Answer:b

20. The code snippet below produces

#include <stdio.h>
void main()
{
1 < 2 ? return 1 : return 2;
}
a) returns 1
b) returns 2
c) Varies
d) Compile time error
Answer:d

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

#include <stdio.h> //Program 1


int main()
{
int d, a = 1, b = 2;
d = a++ + ++b;
printf("%d %d %d", d, a, b);
}
#include <stdio.h> //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) No difference as space doesn’t make any 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
b) Answer:a

22. What is the output of this 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
Answer:b

23. What is the output of this C code?

#include <stdio.h>
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) 6, 4, 6
Answer:a

24. For which of the following, “PI++;” code will fail?


a) #define PI 3.14
b) char *PI = “A”;
c) float PI = 3.14;
d) Both (A) and (B)
Answer:a

25. What is the output of this C code?

#include <stdio.h>
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

26. What is the output of this 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
Answer:a
27. What is the output of this C code?

#include <stdio.h>
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

28. Comment on the output of this C code?

#include <stdio.h>
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) Both a and b
Answer:a

29. #include is called


a) Preprocessor directive
b) Inclusion directive
c) File inclusion directive
d) None of the mentioned
Answer:a

30. C preprocessors can have compiler specific features.


a) true
b) false
c) Depends on the standard
d) Depends on the platform
Answer:a
31. C preprocessor is conceptually the first step during compilation
a) true
b) false
c) Depends on the compiler
d) Depends on the standard
Answer:a

32. Preprocessor feature that supply line numbers and filenames to compiler is called?
a) Selective inclusion
b) macro substitution
c) Concatenation
d) Line control
Answer:d

33. #include are _______ files and #include “somefile.h” ________ files.
a) Library, Library
b) Library, user-created header
c) User-created header, library
d) They can include all types of file
Answer:d

34. A preprocessor is a program


a) That processes its input data to produce output that is used as input to another program
b) That is nothing but a loader
c) That links various source files
d) All of the mentioned
Answer:a

35.The sequence of allocation and deletion of variables for the following code is.

#include <stdio.h>
int main()
{
int a;
{
int b;
}
}

a) a->b, a->b
b) a->b, b->a
c) b->a, a->b
d) b->a, b->a
Answer:b
42. Array sizes are optional during array declaration by using ______ keyword.
a) auto
b) static
c) extern
d) register

43. What is the output of this C code?

#include <stdio.h>
void main()
{
int x = 3;
{
x = 4;
printf("%d", x);
}
}

a) 4
b) 3
c) 0
d) Undefined
Answer:a

44. What is the output of this C code?

#include <stdio.h>
int x = 5;
void main()
{
int x = 3;
m();
printf("%d", x);
}
void m()
{
x = 8;
n();
}
void n()
{
printf("%d", x);
}

a) 8 3
b) 3 8
c) 8 5
d) 5 3
Answer:a
45. What is the output of this C code?

#include <stdio.h>
int x;
void main()
{
m();
printf("%d", x);
}
void m()
{
x = 4;
}

a) 0
b) 4
c) Compile time error
d) Undefined
Answer:b

46. What is the output of this C code?

#include <stdio.h>
static int x = 5;
void main()
{
int x = 9;
{
x = 4;
}
printf("%d", x);
}

a) 9
b) 5
c) 4
d) 0
Answer:c

47. What is the output of this C code?

#include <stdio.h>
void main()
{
{
int x = 8;
}
printf("%d", x);
}

a) 8
b) 0
c) Undefined
d) Compile time error
Answer:d

48.What is the output of this C code?

#include <stdio.h>
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

49. What is the output of this C code?

#include <stdio.h>
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
50. What is the output of this C code?

#include <stdio.h>
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
51. What is the output of this C code(when 1 is entered)?

#include <stdio.h>
void main()
{
double ch;
printf("enter a value btw 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

52. What is the output of this C code(When 1 is entered)?

#include <stdio.h>
void main()
{
char *ch;
printf("enter a value btw 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

53. What is the output of this C code(When 1 is entered)?

#include <stdio.h>
void main()
{
int ch;
printf("enter a value btw 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

54. What is the output of this C code(When 2 is entered)?

#include <stdio.h>
void main()
{
int ch;
printf("enter a value btw 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

55. What is the output of this C code(When 1 is entered)?

#include <stdio.h>
void main()
{
int ch;
printf("enter a value btw 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

56. What is the output of this 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) Compile time error
d) yes no
Answer:c

57. What is the output of this C code?

#include <stdio.h>
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

58. What is the output of this C code?

#include <stdio.h>
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

59. What is the output of this C code?

#include <stdio.h>
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

60.What is the output of this C code?

#include <stdio.h>
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

61. What is the output of this C code?

#include <stdio.h>
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

62. What is the output of this C code?

#include <stdio.h>
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
63. 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

64. What is the value of i and j in the below code?

#include <stdio.h>
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

65. What is the value of i and j in the below code?

#include <stdio.h>
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

66. What is the output of this C code?

#include <stdio.h>
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:a

67. What is the output of this C code?

#include <stdio.h>
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

68. What is the output of this C code?

#include <stdio.h>
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

69. What is the output of this C code?

#include <stdio.h>
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

70. What is the output of this C code?

#include <stdio.h>
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

71.What is the final value of j in the below code?

#include <stdio.h>
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

72. What is the final value of j in the below code?

#include <stdio.h>
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

73. What is the output of this C code?

#include <stdio.h>
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

74. function tolower(c) defined in library works for


a) Ascii character set
b) Unicode character set
c) Ascii and utf-8 but not EBSIDIC character set
d) Any character set
Answer:d

75. What is the output of the below code considering size of short int is 2, char is 1 and int is 4
bytes?

#include <stdio.h>
int main()
{
short int i = 20;
char c = 97;
printf("%d, %d, %d\n", sizeof(i), sizeof(c), sizeof(c + i));
return 0;
}

a) 2, 1, 2
b) 2, 1, 1
c) 2, 1, 4
d) 2, 2, 8
Answer:c

76. Which type conversion is NOT accepted?


a) From char to int
b) From float to char pointer
c) From negative int to char
d) From double to char
View AnswerAnswer:b

77. What will be the data type of the result of the following operation?
(float)a * (int)b / (long)c * (double)d
a) int
b) long
c) float
d) double
Answer:d

78. Which of the following type-casting have chances for wrap around?
a) From int to float
b) From int to char
c) From char to short
d) From char to int
Answer:b

79. Which of the following typecasting is accepted by C?


a) Widening conversions
b) Narrowing conversions
c) Both
d) None of the mentioned
Answer:c

80. When do you need to use type-conversions?


a) The value to be stored is beyond the max limit
b) The value to be stored is in a form not supported by that data type
c) To reduce the memory in use, relevant to the value
d) All of the mentioned
Answer: d

81.Comment on the output of this C code?

#include <stdio.h>
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 compiler
d) None of the mentionedAnswer:b

82. Comment on the output of this C code?

#include <stdio.h>
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) None of the mentionedAnswer:a
83. What is the output of this C code (on a 32-bit machine)?

#include <stdio.h>
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 8Answer:a

84. Which is correct with respect to size of the datatypes?


a) char > int > float
b) int > char > float
c) char < int < double
d) double > char > intAnswer:c

85. What is the output of the following C code(on a 64 bit machine)?

#include <stdio.h>
union Sti
{
int nu;
char m;
};
int main()
{
union Sti s;
printf("%d", sizeof(s));
return 0;
}

a) 8
b) 5
c) 9
d) 4Answer:d

86. What is the output of this C code?

#include <stdio.h>
int main()
{
float x = 'a';
printf("%f", x);
return 0;
}
a) a
b) run time error
c) a.0000000
d) 97.000000

Answer:d

87. Which of the datatypes have size that is variable?


a) int
b) struct
c) float
d) double

Answer:b

88.What is the output of this C code?

#include <stdio.h>
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

89.. The precedence of arithmetic operators is (from highest to lowest)


a) %, *, /, +, -
b) %, +, /, *, -
c) +, -, %, *, /
d) %, +, -, *, /

Answer:a

90. Which of the following is not an arithmetic operation?


a) a *= 10;
b) a /= 10;
c) a != 10;
d) a %= 10;

Answer:c

91. What is the output of this C code?

#include <stdio.h>
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

92. What is the output of this C code?

#include <stdio.h>
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

93. What is the output of this C code?

#include <stdio.h>
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

94. What is the output of this C code?

#include <stdio.h>
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

95. What is the output of this C code?

#include <stdio.h>
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

96. What is the output of this C code?


#include <stdio.h>
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

97. What is the output of this C code?

#include <stdio.h>
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

98. What is the output of this C code?

#include <stdio.h>
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

99. What is the output of the code given below

#include <stdio.h>
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

100. What is the output of this C code?

#include <stdio.h>
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

You might also like