Home

1000+ C Programming Multiple Choice Question Answer [Solved]

Thursday 9th of March 2023

Sharing is caring

1. = and = = have the same operation.
A. True
B. False
C.
D.
Answer : B
2. The output of the following code is:
main() 
{
int k, num = 30;
k = (num > 5 ? (num <= 10 ? 100 : 200) : 500);
printf("
%d", num);
}

A. 200
B. 500
C. 30
D. Unpredictable
Answer : C
3. Which one of the following is not a valid reserved keyword in C++
A. Explicit
B. Public
C. Implicit
D. Private
Answer : C
4. There are total ------ numbers of operators in 'C'.
A. 35
B. 45
C. 55
D. 40
Answer : B
5. Identify the wrong statement
A. putchar(65)
B. putchar('x')
C. putchar("x")
D. putchar('
')
Answer : C
6. All elements of a structure are allocated contiguous memory locations.
A. True
B. False
C.
D.
Answer : A
7. The output of the following code is:
void main() 
{
float a;
int x = 10, y = 3; a = x / y;
printf("%f", a); }

A. 3.999999
B. Error
C. 3
D. 3.000000
Answer : D
8. Which of the following is not a standard exception built in C++.
A. std::bad_creat
B. std::bad_alloc
C. std::bad_cast
D. std::bad_typeid
Answer : A
9. How many times the following loop will execute?
for (a = 0; a < 4; a++)
printf("hello
");

A. 3
B. 4
C. 5
D. infinite
Answer : B
10. Every if statement can be converted into an equivalent switch statement.
A. True
B. False
C.
D.
Answer : B
11.

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


#include 
#define x 5+2
int main(){
int i;
i=x*x*x;
printf("%d",i);
return 0;
}



A. 27
B. 343
C. 233
D. Compiler Error
Answer : A
12. Which of the following is not an infinite loop
A. int i =1;
while (1)
{i++;}
B. for( ; ; );
C. int true=0< false;
while (true)
{false = 1;}
D. int y, x = 0;
do
{y = x;}
while (x==0);
Answer : C
13. Which of the following correctly describes C++ language?
A. Statically typed language
B. Dynamically typed language
C. Both Statically and dynamically typed language
D. Type-less language
Answer : D
14. The output of the following code is:
void main() 
{
char a = 'B';
switch (a)
{
case 'A' : printf("a");
case 'B' : printf("b");
default : printf("c");
}

A. B
B. b
C. bca
D. bc
Answer : D
15. emp name' is a valid variable name.
A. True
B. False
C.
D.
Answer : B
16. enum helps to create user defined datatype.
A. True
B. False
C.
D.
Answer : A
17. The identifier argv[] is a pointer to an array of strings.
A. True
B. False
C.
D.
Answer : B
18. What will be output if you will compile and execute the following c code?
#include 
int main(){
int i=320;
char *ptr=(char *)&i;
printf("%d",*ptr);
return 0;
}

A. 1
B. 64
C. 320
D. Compiler Error
Answer : B
19. Which header file is essential for using strcmp() function?
A. string.h
B. strings.h
C. text.h
D. strcmp.h
Answer : A
20. What is Keywords?
A. Keywords have some predefine meanings and these meanings can be changed.
B. Keywords have some unknown meanings and these meanings cannot be changed.
C. Keywords have some predefine meanings and these meanings cannot be changed.
D. None of the above
Answer : C
21. The output of the following code is:
main() 
{
int a = 0;
for (; i = 0; i++)
printf("%d", a);
}

A. 0
B. Nothing will be displayed
C. Infinite loop
D. None of the above
Answer : D
22. fprintf()function can be used to write into console.
A. True
B. False
C.
D.
Answer : B
23. char *s[10] defines an array of ------------------------
A. pointers to strings
B. string to pointer
C. both
D.
Answer : A
24. What would be the output of the following program?
int x=40;
main(){
int x=20;
printf("
%d",x);
}

A. 40
B. 20
C. Compilation Error
D. Garbeg Value
Answer : B
25. The output of the following code is:
main() 
{
void msg()
{
printf("HELLO WORLD");
}
}

A. HELLO WORLD
B. Error
C. None of the above
D. Null
Answer : B
26. Which escape character can be used to beep from speaker in C?
A. \a
B. \b
C. \m
D.
Answer : A
27. Which of the following expressions is wrong
A. float a =123.56;
B. char ch ='T' * 'A';
C. char ch ='T' *20;
D. 3 +a = b;
Answer : D
28. The output of the following code is:
void main() 
{
int a = 1, b=2;
int *ip;
ip=&a;
b=*ip;
printf("%d", b);
}

A. 2
B. 1
C. 100
D. 0
Answer : B
29. The output of the following code is:
void main() 
{
int a = 0;
while (a<=50) for(;;) if(++a % 50==0) break;
printf("a = %d", a);
}

A. a = 100
B. a = 50
C. compilation error
D. runtime error
Answer : A
30. Left shift operator rotates the bits on the left and places them to the right.
A. True
B. False
C.
D.
Answer : B
31. Which one of the following is not a fundamental data type in C++
A. float
B. string
C. int
D. wchar_t
Answer : A
32. For 16?bit compiler allowable range for integer constants is ______ ?
A. ?3.4e38 to 3.4e38
B. ?32767 to 32768
C. ?32768 to 32767
D. ?32668 to 32667
Answer : C
33. The main() function can call itself recursively.
A. True
B. False
C.
D.
Answer : A
34. do-while loop is useful when we want the statements within the loop must be executed
A. Only once
B. At least once
C. More than Once
D. Any one of the above
Answer : B
35. Which of the following shows the correct hierarchy of arithmetic operations in C
A. / + * ?
B. * ? / +
C. + ? / *
D. * / + -
Answer : D
36. continue statement is used
A. to go to the next iteration in a loop
B. come out of a loop
C. exit and return to the main function
D. restarts iterations from beginning of loop
Answer : D
37. What is an array?
A. An array is a collection of variables that are of the dissimilar data type.
B. An array is a collection of variables that are of the same data type.
C. An array is not a collection of variables that are of the same data type.
D. None of the above.
Answer : B
38. If the class name is X, what is the type of its “this” pointer (in a nonstatic, non-const member function)?
A. const X* const
B. X* const
C. X*
D. X&
Answer : D
39. In the expression - 'x + y + 3z =20'
A. x + y' is a keyword
B. 3 and 20 are constants
C. 3z is a constant
D. y is a variable and z is a constant
Answer : B
40. The output of the following code is:
void main()
{
int a = 20;
printf("%d\t%d
", ++a, a);
}

A. 21 21
B. 20 21
C. 21 20
D. 20 20
Answer : C
41. Bitwise operators can operate upon?
A. double and chars
B. floats and doubles
C. ints and floats
D. ints and chars
Answer : D
42. The output of the following code is:
void main() 
{
static int a = 1, b, c;
if (a>=2) b=2; c=3;
printf("%d\t%d", b,c);
}

A. 2 3
B. 0 3
C. 0 0
D. 2 0
Answer : B
43. Which of the STL containers store the elements contiguously (in adjecent memory locations)?
A. std::vector
B. std::list
C. std::map
D. std::set
Answer : C
44. Which of the following keyword supports dynamic method resolution?
A. abstract
B. Virtual
C. Dynamic
D. Typeid
Answer : A
45. Which of the following language is predecessor to C Programming Language?
A. A
B. B
C. BCPL
D. C++
Answer : B
46. Which of the following is invalid?
A. ''
B. " "
C. 'a'
D. abc'
Answer : D
47. Which of the following is the most preferred way of throwing and handling exceptions?
A. Throw by value and catch by reference.
B. Throw by reference and catch by reference.
C. Throw by value and catch by value
D. Throw the pointer value and provide catch for teh pointer type.
Answer : B
48. The -------------------------- loop executes at least once.
A. for
B. while
C. do-while
D. while & do-while
Answer : C
49. Which of the following is a valid destructor of the class name "Country"
A. int ~Country()
B. void Country()
C. int ~Country(Country obj)
D. void ~Country()
Answer : B
50. Operation between an integer and float always yields a float result.
A. True
B. False
C.
D.
Answer : A

Sharing is caring