Home

1000+ C Programming Multiple Choice Question Answer [Solved]

Thursday 9th of March 2023

Sharing is caring

1. A multidimensional array A[10][9] can store-------- number of elements
A. 91
B. 88
C. 90
D. 89
Answer : C
2. A declaration float a, b; occupies ___ of memory
A. 1 byte
B. 4 bytes
C. 8 bytes
D. 16 bytes
Answer : C
3. The output of the following code is:
void main() 
{
int a;
int &b = a;
a=100;
printf("b=%d\ta=%d
", b,a);
}

A. b=100 a=100
B. b=100 a=0
C. b=0 a=100
D. Error
Answer : D
4. Which of the following keyword supports dynamic method resolution?
A. abstract
B. Virtual
C. Dynamic
D. Typeid
Answer : A
5. = and = = have the same operation.
A. True
B. False
C.
D.
Answer : B
6. unsigned char has a range from 0 to ------------
A. 253
B. 254
C. 255
D. 256
Answer : C
7. The default initial value of automatic storage class is 0.
A. True
B. False
C.
D.
Answer : B
8. printf("%d", sizeof('2')); will print 2.
A. True
B. False
C.
D.
Answer : B
9. The-------------------- statement helps immediate exit from any part of the loop
A. break
B. continue
C. exit
D. All of the above
Answer : A
10. What's wrong? while( (i < 10) && (i > 24))
A. the logical operator && cannot be used in a test condition
B. the while loop is an exit-condition loop
C. the test condition is always true
D. the test condition is always false
Answer : D
11. Character data types cannot be declared as unsigned.
A. True
B. False
C.
D.
Answer : B
12. Structures within structures cannot be created.
A. True
B. False
C.
D.
Answer : B
13. 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
14. void' is a datatype.
A. True
B. False
C.
D.
Answer : A
15. The -------------------------- loop executes at least once.
A. for
B. while
C. do-while
D. while & do-while
Answer : C
16. perror( ) function used to ?
A. Work same as printf()
B. prints the error message specified by the compiler
C. prints the garbage value assigned by the compiler
D. None of the above
Answer : B
17. Which of the following is not a preprocessor directive
A. #if
B. #elseif
C. #undef
D. #pragma
Answer : B
18. # define PI = 8;' is the correct declaration of macros.
A. True
B. False
C.
D.
Answer : B
19. Only one break can be used in one loop.
A. True
B. False
C.
D.
Answer : B
20. No commas or blanks are allowed within an integer or a real constant.
A. True
B. False
C.
D.
Answer : A
21. The expression "int i = j = k = 0;" is invalid.
A. True
B. False
C.
D.
Answer : A
22. The same variable names of automatic type can be used in different functions without any conflict.
A. True
B. False
C.
D.
Answer : A
23. && and & operators have the same meaning.
A. True
B. False
C.
D.
Answer : B
24. What's wrong? for (int k = 2, k <=12, k++)
A. the increment should always be ++k
B. the variable must always be the letter i when using a for loop
C. there should be a semicolon at the end of the statement
D. the commas should be semicolons
Answer : B
25. What is the difference between overloaded functions and overridden functions?
A. Overloading is a dynamic or run-time binding and Overriding is static or compile-time binding
B. Redefining a function in a friend class is called function overriding while Redefining a function in a derived class is called a overloaded fucntion.
C. Overloading is a static or compile-time binding and Overriding is dynamic or run-time binding
D. Redefining a function in a friend class is called function overloading while Redefining a function in a derived class is called as overridden fucnion.
Answer : B
26. Single operations involving entire arrays are permitted in C.
A. True
B. False
C.
D.
Answer : A
27. What will be output if you will compile and execute the following c code?
#include 
int main()
{
float a=5.2;
if(a==5.2)
printf("Equal");
else if(a<5.2)
printf("Less than");
else
printf("Greater than");
return 0;
}

A. Less than
B. Equal
C.

Greater than


D. None of above
Answer : A
28. Which header file is essential for using strcmp() function?
A. string.h
B. strings.h
C. text.h
D. strcmp.h
Answer : A
29. 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
30. A pointer is an indication of the variable to be accessed next.
A. True
B. False
C.
D.
Answer : B
31. What's wrong? (x = 4 && y = 5) ? (a = 5) ; (b = 6);
A. the question mark should be an equal sign
B. the first semicolon should be a colon
C. there are too many variables in the statement
D. the conditional operator is only used with apstrings
Answer : D
32. fopen() function returns a pointer to the open file.
A. True
B. False
C.
D.
Answer : A
33. static variable will not always have assigned value.
A. True
B. False
C.
D.
Answer : A
34. char *s[10] defines an array of ------------------------
A. pointers to strings
B. string to pointer
C. both
D.
Answer : A
35. Which of the following language is predecessor to C Programming Language?
A. A
B. B
C. BCPL
D. C++
Answer : B
36. The output of the following code is:
main() 
{
int a[10], i;
for (i = 1; I <= 0; i++)
{
scanf("%d", a[i]);
printf("%d", a[i]);
}
}

A. 10
B. Logical error
C. Runtime error
D. 1 to 10 will be displayed
Answer : B
37. ------ is the ternary operator
A. ?,-
B. ?,:
C. ++<--
D. none of the above
Answer : B
38. 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
39. 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
40. All macro substitutions in a program are done before compilation of the program.
A. True
B. False
C.
D.
Answer : A
41. The size of signed integer is ------ bytes.
A. 4
B. 2
C. 8
D. 10
Answer : B
42. The output of the following code is:
#define sqr(x= x*x) 
main()
{
int a = 10, b = 5;
printf("%d, %d", sqr(a+b),sqr(++a));
}

A. 77, 121
B. 225, 121
C. 77< 144
D. Compilation error
Answer : D
43. Which options shows the correct hierarchy of arithmetic operators
A. **, * or /, + or -
B. **, *, /, +, -
C. **< /< *< +<-
D. / or *, - or +
Answer : D
44. 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
45. 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
46. When is std::bad_alloc exception thrown?
A. When new operator cannot allocate memory
B. When alloc function fails
C. When type requested for new operation is considered bad<  thisexception is thrown
D. When delete operator cannot delete teh allocated (corrupted) object
Answer : D
47. struct stud
{
int roll;
char name[20];
float marks;
} *p;
What will be the byte size of p?

A. 24
B. 2
C. 26
D. None
Answer : B
48. The output of the following code is:
int f(int a, int b); 
void main()
{
int a = 12, b=154;
printf("%d", f(a, b));
}
int f(int a, int b)
{
if (a<b) return(f(b, a));
if(b==0) return(a);
return (f(b, a % b));
}

A. 2
B. 1
C. Compilation error
D. Runtime error
Answer : A
49. If 'str' is a string of 7 characters, the statement printf("%4s", str); will display ------characters.
A. 4
B. 7
C. 6
D. 0
Answer : A
50. 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

Sharing is caring