100 Multiple Choice Questions in C programming

Hello, Coders! In this post, we will discuss the 100 Multiple choice questions in C programming. As we all know that C is the most basic language that every technical student must be well versed with. We have included all kinds of questions that can be asked related to C programming.

100 Multiple choice questions in C programming.

Q1. Property which allows producing different executable for different platforms
in C is called?
A. File inclusion B. Selective inclusion
C. Conditional compilation D. Recursive macros
Answer: Option C
Explanation: Conditional compilation is the preprocessor facility to produce different
executable.

Q2. C preprocessors can have compiler-specific features.
A. true B. false C. Depends on the standard D. Depends on the platform
Answer: Option A Explanation: pragma is a compiler-specific feature.

Q3.The preprocessor feature that supplies line numbers and file names to the compiler is
called?
A. Selective inclusion B. macro substitution C. Concatenation D. Line control
Answer: Option D
Explanation: Theory concept

Q4. Which of the following are C preprocessors?
A. #ifdef B. #define C. #endif D. All of the mentioned.
Answer: Option D
Explanation: Theory concept

Q5.The C-preprocessors are specified with _________symbol.
A. # B. $ C. ” ” D. None of the mentioned.
Answer: Option A
Explanation: The C-preprocessors are specified with # symbol

Q6. What is the output of this C code?

#define a 20
int main()
{
const int a = 50;
printf("a = %d\n", a);
}

A. a = 50 B. a = 20 C. Run time error D. Compilation Error
Answer: Option D
Explanation: The #define substitutes a with 20 leaving no identifier and hence the compilation
error. Code Comipiled Here

Q7. What is the output of this C code?

int main()
{
int var = 010;
printf("%d", var);
}

A. 2 B. 8 C. 9 D. 10
Answer: Option B
Explanation: 010 is an octal representation of 8. Check Output

Q8. enum types are processed by?
A. Compiler B. Preprocessor C. Linker D. Assembler
Answer: Option A
Explanation: Theory concept

Q9. What is the output of this C code?

int main()
{
printf("AllIndiaExams\r\nclass\n");
return 0;
} 

A. AllIndiaExamsclass B. AllIndiaExamsclass C. classundry D. AllIndiaExams
Answer: Option B
Explanation: rn combination makes cursor move to nextline. Run Code Here

Q10. Predict the output or error(s) for the following:

	void main()
{
	int const * p=5;
	printf("%d",++(*p));
}
 

A. Compile time error B. 5 C. Runtime Error D. None of these

Answer: Compiler error: Cannot modify a constant value. Explanation:  p is a pointer to a “constant integer”. But we tried to change the value of the “constant integer”. Run Code Here

Q11. Predict the output or error(s) for the following:

	main()
{
	char s[ ]="man";
	int i;
	for(i=0;s[ i ];i++)
	printf("\n%c%c%c%c",s[ i ],*(s+i),*(i+s),i[s]);
}

A. Compile time error B. mmmm aaa nnn C. Runtime Error D. man nna mma

Answer: mmmm aaaa nnnn Explanation: s[i], *(i+s), *(s+i), i[s] are all different ways of expressing the same idea. Generally, the array name is the base address for that array. Here s is the base address. i is the index number/displacement from the base address. So, indirecting it with * is the same as s[i]. i[s] may be surprising. But in the case of  C, it is the same as s[i]. Run Code Here

Q12. Predict the output or error(s) for the following:

	main()
{
	float me = 1.1;
	double you = 1.1;
	if(me==you)
printf("I love U");
else
		printf("I hate U");
}

A. Compile time error B. I hate U C. Runtime Error D. I love U

Answer: I hate U Explanation: For floating-point numbers (float, double, long double) the values cannot be predicted exactly. Depending on the number of bytes, the precession with of the value represented varies. Float takes 4 bytes and long double takes 10 bytes. So float stores 0.9 with less precision than long double. Run Code Here

Q13.The name of the variable used in one function cannot be used in another
function?
A. True B. False C. Maybe D. None of the mentioned.
Answer: Option B
Explanation: Since the scope of the variable declared within a function is restricted only within
that function, the same name can be used to declare another variable in another
function.

Q14. C99 standard guarantees the uniqueness of __ characters for internal names.
A. 31 B. 63 C. 12 D. 14
Answer: Option B
Explanation: ISO C99 compiler may consider only the first 63 characters for internal.

Q15. 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: Option B
Explanation: Variable name cannot start with a digit.

Q16. All keywords in C are in?
A. Lower Case letters B. Upper Case letters C. Camel Case letters D. None
Answer: Option A
Explanation: Theory Concept

Q17. Variable name resolving (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
Answer: Option A
Explanation: It depends on the standard to which compiler and linkers are adhering.

Q18. 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: Option D
Explanation: Since, it doesn’t allow any other special character in a variable name, it results in an error

Q19. Which is a 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: Option B
Explanation: We cannot use space, comma, and $ in a variable name.

Q20. 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: Option D
Explanation: define PI 3.14 as a macro preprocessor, it is a textual substitution.

Q21. Which of the following cannot be a variable name in C?
A. Volatile B. True C. friend D. export
Answer: Option A
Explanation: volatile is a C keyword.

Q22. What is the output of this C code?

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. Runtime Error D. None of these
Answer: Option A
Explanation: Since we have defined y, redefining it results in an error.
Output: $ cc pgm2.c Run Code Here

Q23. What is the output of this C code?

int foo();
 int main()
 {
 int i = foo();
 }
 foo()
 {
 printf("2 ");
 return 2;
 }

A. 2 B. Compile time error C. Depends on the compiler D. Depends on the standard
Answer: Option A . Run Code Here

Q24. Which keyword is used to come out of a loop only for that iteration?
A. break B. continue C. return D. None of the mentioned
Answer: Option B
Explanation: Theory Concept

Q25.What is the output of this C code?

void main()
 {
 double k = 0;
 for (k = 0.0; k < 3.0; k++)
 printf("Hello");
 }

A. Run time error B. Hello, will be printed thrice C. Compile Time error D. Hello can be printed infinitely
Answer: Option B
Explanation: As, the loop iterates 3 times, Hello is printed thrice. Run Code Here

Q26. typedef which of the following may create a problem in the program?
A. ; B. printf/scanf C. Arithmetic operators D. All of the mentioned.
Answer: Option D
Explanation: Theory Concept

Q27. typedef declaration:
A. Does not create a new type B. It merely adds a new name for some existing type. C. Both a & b D. None of the mentioned
Answer: Option C

Q28. What is the output of this C code?

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

A. Compile time error B. 1 2 3 4 5 C. Runtime Error D. 5 4 3 2 1

Answer: 5 4 3 2 1
Explanation: When a static storage class is given, it is initialized once. The change in the
value of a static variable is retained even between the function calls. Main is also treated
like any other ordinary function, which can be called recursively. Run Code Here

Q29. What is the output of this C code?

main() 
{ 
 int c[ ]={2.8,3.4,4,6.7,5}; 
 int j,*p=c,*q=c; 
 for(j=0;j<5;j++) { 
 printf(" %d ",*c); 
 ++q; } 
 for(j=0;j<5;j++){ 
printf(" %d ",*p); 14 
++p; } 
}

A. Compile time error B.3 4 6 5 2 2 2 2 2 C. Runtime Error D. 2 2 2 2 2 2 3 4 6 5

Answer: 2 2 2 2 2 2 3 4 6 5
Explanation: Initially pointer c is assigned to both p and q. In the first loop, since only q
is incremented and not c, the value 2 will be printed 5 times. In the second loop p, itself is
incremented. So the values 2 3 4 6 5 will be printed.

Q30. What is the output of this C code?

main() 
{ 
 extern int i; 
 i=20; 
printf("%d",i); 
}

A. Compile time error B. Linker Error C. Runtime Error D. 20

Answer: Linker Error: Undefined symbol ‘_i’
Explanation: extern storage class in the following declaration, extern int i; the linker finds
that no other variable of name i is available in any other program with memory space
allocated for it. Hence a linker error has occurred.

Q31. What is the output of this C code?

main() 
{ 
 int i=-1,j=-1,k=0,l=2,m; 
 m=i++&&j++&&k++||l++; 
 printf("%d %d %d %d %d",i,j,k,l,m); 
} 

A. Compile time error B. 1 3 1 0 0 C. Runtime Error D. 0 0 1 3 1

Answer: 0 0 1 3 1
Explanation: Logical operations always give a result of 1 or 0. And also the logical
AND (&&) operator has higher priority over the logical OR (||) operator. So the
expression ‘i++ && j++ && k++’ is executed first. The result of this expression is 0
(-1 && -1 && 0 = 0). Now the expression is 0 || 2 which evaluates to 1 (because OR
operator always gives 1 except for ‘0 || 0’ combination- for which it gives 0). So the value
of m is 1. The values of other variables are also incremented by 1.

Q32. What is the output of this C code?

main() 
{ 
 int i=3; 
 switch(i) 
 { 
 default:printf("zero"); 
 case 1: printf("one"); 
 break; 
 case 2:printf("two"); 
 break; 
 case 3: printf("three"); 
 break; 
 } 
} 

A. Compile time error B. Three C. Two D. One

Answer: three
Explanation: The default case can be placed anywhere inside the loop. It is executed
only when all other cases don’t match.

Q33. What is the output of this C code?

main() 
{ 
 printf("%x",-1<<4); 
}

A. 0 1 2 3 4 B. 0ffff C. fff0 D. 0 0 1 3 1

Answer: fff0
Explanation:-1 is internally represented as all 1’s. When left shifted four times the least
significant 4 bits are filled with 0’s.The %x format specifier specifies that the integer
value is printed as a hexadecimal value.

Q34. What is the output of this C code?

main() 
{ 
 int c=- -2; 
 printf("c=%d",c); 
}

A. Compile time error B.2 C. -2 D. 0

Answer: c=2;
Explanation: Here unary minus (or negation) operator is used twice. Same maths rules
applies, ie. minus * minus= plus.

Q35. What is the output of this C code?

#define int char 
main() 
{ 
 int i=65; 
 printf("sizeof(i)=%d",sizeof(i)); 
}

A. Compile time error B. sizeof(i)=2 C. sizeof(i)=1 D. None of Above

Answer: sizeof(i)=1
Explanation: Since the #define replaces the string int by the macro char

Q36. What is the output of this C code?

#include<stdio.h> 
main() 
{ 
char s[]={'a','b','c','\n','c','\0'}; 
char *p,*str,*str1; 
p=&s[3]; 
str=p; 
str1=s; 
printf("%d",++*p + ++*str1-32); 
} 

A. Compile time error B. 77 C. 33 D. None of Above

Answer: 77
Explanation: p is pointing to character ‘\n’. str1 is pointing to character ‘a’ ++p. “p is pointing to ‘\n’ and that is incremented by one.” the ASCII value of ‘\n’ is 10, which is then incremented to 11. The value of ++p is 11. ++*str1, str1 is pointing to ‘a’ that is incremented by 1 and it becomes ‘b’. ASCII value of ‘b’ is 98.
Now performing (11 + 98 – 32), we get 77(“M”);
So we get the output 77 :: “M” (Ascii is 77).

Q37. What is the output of this C code?

#include<stdio.h> 
main() 
{ 
int a[2][2][2] = { {10,2,3,4}, {5,6,7,8} }; 
int *p,*q; 
p=&a[2][2][2]; 
*q=***a; 
printf("%d----%d",*p,*q); 
}

A. Compile time error B. Run Time error C. 5, 6, 7, 8 D. Garbage Value

Answer: SomeGarbageValue—1
Explanation: p=&a[2][2][2] you declare only two 2D arrays, but you are trying to
access the third 2D(which you are not declared) it will print garbage values. q=**a
starting address of a is assigned integer pointer. Now q is pointing to starting address of a.
If you print *q, it will print first element of 3D array.

Q38. What is the output of this C code?

#include<stdio.h> 
main() 
{ 
struct xx 
{ 
int x; 
struct yy 
{ 
char s; 
 struct xx *p; 
}; 
struct yy *q; 
}; 
} 

A. Compile time error B. pq C. ppqq D. None of Above

Answer: Compiler Error
Explanation: The structure yy is nested within structure xx. Hence, the elements are of
yy are to be accessed through the instance of structure xx, which needs an instance of yy
to be known. If the instance is created after defining the structure the compiler will not
know about the instance relative to xx. Hence for nested structure yy you have to declare
a member.

Q39. What is the output of this C code?

main() 
{ 
printf("\nab"); 
printf("\bsi"); 
printf("\rha"); 
}

A. Compile time error B. hai C. sab D. rsb

Answer: hai
Explanation:
\n – newline
\b – backspace
\r – linefeed

Q40. What is the output of this C code?

main() 
{ 
int i=5; 
printf("%d%d%d%d%d%d",i++,i--,++i,--i,i); 
} 

A. Compile time error B. 55454 C. 554544 D. 45545

Answer: 45545
Explanation: The arguments in a function call are pushed into the stack from left to
right. The evaluation is by popping out from the stack. and the evaluation is from right to
left, hence the result.

Q41. What is the output of this C code?

#define square(x) x*x 
main() 
{ 
int i; 
i = 64/square(4); 
printf("%d",i); 
}  

A. Compile time error B. 64 C. 46 D. 0

Answer: 64
Explanation: The macro call square(4) will be substituted by 44 so the expression becomes i = 64/44. Since / and * has equal priority the expression will be evaluated as (64/4)4 i.e. 164 = 64

Q42. What is the output of this C code?

main() 
{ 
char *p="hai friends",*p1; 
p1=p; 
while(*p!='\0') ++*p++; 
printf("%s %s",p,p1); 
}

A. Compile time error B. ibjsjfoet C. ibj!gsjet D. ibj!gsjfoet

Answer: ibj!gsjfoet
Explanation: ++*p++ will be parsed in the given order

Q43. What is the output of this C code?

#include <stdio.h> 
#define a 10 
main() 
{ 
#define a 50 
printf("%d",a); 
}

A. Compile time error B. 40 C. 50 D. 60

Answer: 50
Explanation: The preprocessor directives can be redefined anywhere in the program. So
the most recently assigned value will be taken.

Q44. What is the output of this C code?

. main() 
{ 
printf("%p",main); 
}

A. Compile time error B. Garbage Value C. Infinite loop D. Some address will be printed.

Answer: Some address will be printed.
Explanation: Function names are just addresses (just like array names are addresses).
main() is also a function. So the address of function main will be printed. %p in printf
specifies that the argument is an address. They are printed as hexadecimal numbers.

Q45. What is the output of this C code?

main() 
{ 
clrscr(); 
} 
clrscr(); 

A. Compile time error B. 0 C. Infinite D. No output

Answer: No output/error
Explanation: The first clrscr() occurs inside a function. So it becomes a function call. In
the second clrscr(); is a function declaration (because it is not inside any
function).

Q46. What is the output of this C code?

enum colors {BLACK,BLUE,GREEN} 
 main() 
{ 
 
 printf("%d..%d..%d",BLACK,BLUE,GREEN); 
 
 return(1); 
} 

A. Compile time error B. 0 C. Infinite D. 0 1 2

Answer: 0..1..2
Explanation: enum assigns numbers starting from 0, if not explicitly defined.

Q47. What is the output of this C code?

main() 
{ 
 char *p; 
 p="Hello"; 
 printf("%c\n",*&*p); 
}  

A. Run Time error B. llo C. Hello D. H

Answer: H
Explanation: * is a dereference operator & is a reference operator. They can be
applied any number of times provided it is meaningful. Here p points to the first character in the string “Hello”. *p dereferences it and so its value is H. Again & references it to an address and * dereferences it to the value H.

Q48. What is the output of this C code?

void main() 
{ 
 int i=5; 
 printf("%d",i++ + ++i); 
}  

A. Compile time error B. 0 C. 5 D. Cannot be predicted

Answer: Output Cannot be predicted exactly.
Explanation: Side effects are involved in the evaluation of i

Q49. What is the output of this C code?

void main() 
{ 
 int i=5; 
 printf("%d",i+++++i); 
} 

A. Compile time error B. 0 C. Infinite D. 5

Answer: Compiler Error
Explanation: The expression i+++++i is parsed as i ++ ++ + i which is an illegal
combination of operators.

Q50. What is the output of this C code?

main() 
{ 
int i; 
printf("%d",scanf("%d",&i)); // value 10 is given as input here 
}  

A. -1 B. 0 C. 1 D. No output

Answer: 1
Explanation: Scanf returns the number of items successfully read and not 1/0. Here 10 is
given as input which should have been scanned successfully. So, the number of items read is 1.

Q51. Strings are character arrays. The last index contains the null-terminated
character

  1. \t
  2. \1
  3. \0
  4. \n

Answer: \0 Explanation: Theory Concept

Q52. Which of the following is a collection of different data types?

  1. String
  2. Structure
  3. Array
  4. Files

Answer: Structure Explanation: Theory Concept

Q53. int **ptr; is?

A. Pointer to integer B. None of these C. Pointer to pointer D. Invalid declaration
Answer: Pointer to pointer Explanation: Theory Concept

Q54. What is the output of this C code?

#define f(g,g2) g##g2 
main() 
{ 
int var12=100; 
printf("%d",f(var,12)); 
 } 

A. Compile time error B. 101 C. 100 D. 99

Answer: 100

Q55.What is the output of this C code?

main() 
{ 
int i=0; 
 
for(;i++;printf("%d",i)) ; 
printf("%d",i); 
}

A. Compile time error B. 0 C. Infinite D. 1

Answer: 1
Explanation: before entering into the for loop the checking condition is “evaluated”.
Here it evaluates to 0 (false) and comes out of the loop, and i is
incremented (note the semicolon after the for loop).

Q56. What is the output of this C code?

#include<stdio.h> 
main() 
{ 
 char s[]={'a','b','c','\n','c','\0'}; 
 char *p,*str,*str1; 
 p=&s[3]; 
 str=p; 
 str1=s; 
 printf("%d",++*p + ++*str1-32); 
}  

A. No Output B. 0 C. N D. M

Answer: M
Explanation: p is pointing to character ‘\n’.str1 is pointing to character ‘a’ ++p. p is pointing to ‘\n’ and that is incremented by one.” the ASCII value of ‘\n’ is 10. then it is incremented to 11. the value of ++p is 11.
++*str1-“str1 is pointing to ‘a’ that is incremented by 1 and it becomes ‘b’. ASCII value of ‘b’ is 98. both 11 and 98 are added and the result is subtracted from 32.
i.e. (11+98-32)=77(“M”);

Q57. What is the output of this C code?

main() 
{ 
 show(); 
} 
void show() 
{ 
 printf("I'm the greatest"); 
} 

A. Compile time error B. 0 C. Infinite D. No output

Answer: Compiler error: Type mismatch in redeclaration of show.
Explanation: When the compiler sees the function show it doesn’t know anything about
it. So the default return type (ie, int) is assumed. But when the compiler sees the actual definition of show mismatch occurs since it is declared as void.
Hence the error.

Q58. What is the output of this C code?

main() 
 { 
 int i=-1; 
 +i; 
 printf("i = %d, +i = %d \n",i,+i); 
 }  

A. Compile time error B. 1.-1 C. 1,1 D. -1,-1

Answer: i = -1, +i = -1
Explanation: Unary + is the only dummy operator in C. Where-ever it comes you can
just ignore it just because it has no effect on the expressions.

Q59. How scanf will execute?

main() 
 { 
 char name[10],s[12]; 
 scanf(" \"%[^\"]\"",s); 
 } 

Answer: First it checks for the leading white space and discards it. Then it matches
with a quotation mark and then it reads all character up to another
quotation mark.

Q60. What is the problem with the following code segment?

while ((fgets(receiving array,50,file_ptr)) != EOF) 

Answer & Explanation:
fgets returns a pointer. So the correct end of file check is checking for !=NULL

Q61.What is the output of this C code?

main() 
 { 
 main(); 
 } 

A. Compile time error B. 1 C. 0 D. Runtime Error

Answer: Runtime error
Explanation: the main function calls itself again and again. Each time the function is called
its return address is stored in the call stack. Since there is no condition to
terminate the function call, the call stack overflows at runtime. So it
terminates the program and results in an error.

Q62. What is the output of this C code?

main() 
 { 
 int *j; 
 { 
 int i=10; 
 j=&i; 
 } 
 printf("%d",*j); 
}

A. Compile time error B. 10 C. 9 D. 8

Answer: 10
Explanation: The variable i is a block-level variable and the visibility is inside that
block only. But the lifetime of i is a lifetime of the function so it lives up to
the exit of the main function. Since i is still allocated space, *j prints the value stored in i since j points i.

Q63. What is the output of this C code?

main() 
 { 
 int i=-1; 
 -i; 
 printf("i = %d, -i = %d \n",i,-i); 
 }  

A. Compile time error B. 1.-1 C. -1,1 D. -1,-1

Answer: i = -1, -i = 1
Explanation: -i is executed and this execution doesn’t affect the value of i. In printf first,
you just print the value of i. After that the value of the expression -i = -(-1

Q64. What is the output of this C code?

#include<stdio.h> 
main() 
 { 
 const int i=4; 
 float j; 
 j = ++i; 
 printf("%d %f", i,++j); 
 }  

A. Compile time error B. Runtime error C. 1 D. 0

Answer: Compiler error
Explanation: i is a constant. you cannot change the value of constant

Q65. What is the output of this C code?

main() 
{ 
 int i=5,j=6,z; 
 printf("%d",i+++j); 
 } 

A. Compile time error B. 11 C. 10 D. Infinite

Answer: 11
Explanation: the expression i+++j is treated as (i++ + j)

Q66. What is the output of this C code?

main() 
{ 
 int i=_l_abc(10); 
 printf("%d\n",--i); 
} 
int _l_abc(int i) 
{ 
 return(i++); 
} 

A. Compile time error B. 11 C. 10 D.9

Answer: 9
Explanation: return(i++) it will first return i and then increments. i.e. 10 will be
returned.

Q67. What is the output of this C code?

main() 
{ 
 char *p; 
 int *q; 
 long *r; 
 p=q=r=0; 
 p++; 
 q++; 
 r++; 
 printf("%p...%p...%p",p,q,r); 
}

Answer: 0001…0002…0004
Explanation: ++ operator when applied to pointers increments address according to
their corresponding data types.

Q68. What is the output of this C code?

main(int argc, char **argv) 
{ 
 printf("enter the character"); 
 getchar(); 
 sum(argv[1],argv[2]); 
} 
sum(num1,num2) 
int num1,num2; 
{ 
 return num1+num2; 
} 

A. Compile time error B. Runtime error C. -1 D. Infinite

Answer: Compiler error.
Explanation: argv[1] & argv[2] are strings. They are passed to the function sum without
converting it to integer values.

Q69. What is the output of this C code?

# include <stdio.h> 
int one_d[]={1,2,3}; 
main() 
{ 
 int *ptr; 
 ptr=one_d; 
 ptr+=3; 
 printf("%d",*ptr); 
} 

A. Compile time error B. garbage value C. Null Value D. Infinite

Answer: garbage value
Explanation: ptr pointer is pointing to out of the array range of one_d.

Q70. What is the output of this C code?

#include<stdio.h> 
main() 
{ 
FILE *ptr; 
char i; 
ptr=fopen("zzz.c","r"); 
while((i=fgetch(ptr))!=EOF) 
printf("%c",i); 
}  

Answer: Contents of zzz.c followed by an infinite loop
Explanation: The condition is checked against EOF, it should be checked against NULL.

Q71. What is the output of this C code?

 main() 
{ 
 int i; 
 i = abc(); 
 printf("%d",i); 
} 
abc() 
{ 
 _AX = 1000; 
} 

A. Compile time error B. 999 C. Null Value D.1000

Answer: 1000
Explanation: Normally the return value from the function is through the information
from the accumulator. Here _AH is the pseudo global variable denoting the accumulator. Hence, the value of the accumulator is set 1000 so the function returns value 1000.

Q72. What is the output of this C code?

int i; 
 main(){ 
int t; 
for ( t=4;scanf("%d",&i)-t;printf("%d\n",i)) 
 printf("%d--",t--); 
 } 
 // If the inputs are 0,1,2,3 find the o/p 

Answer:
4–0
3–1
2–2
Explanation:
Let us assume some x= scanf(“%d”,&i)-t the values during execution
will be,
t i x
4 0 -4
3 1 -2
2 2 0

Q73. What is the output of this C code?

main(){ 
 int a= 0;int b = 20;char x =1;char y =10; 
 if(a,b,x,y) 
 printf("hello"); 
 }

A. Compile time error B. hello C. olleh D.0

Answer: hello
Explanation: The comma operator has associativity from left to right. Only the
rightmost value is returned and the other values are evaluated and ignored. Thus the value of the last variable y is returned to check in if. Since it is a non-zero value if becomes true so, “hello” will be printed.

Q74. What is the output of this C code?

 main(){ 
 unsigned int i; 
 for(i=1;i>-2;i--) 
 printf("c aptitude"); 
} 

Explanation: i is an unsigned integer. It is compared with a signed value. Since both
types don’t match, signed is promoted to unsigned value. The unsigned equivalent of -2 is a huge value so the condition becomes false and control comes out of the loop.

Q75. What is the output of this C code?

main() 
{ 
char *p; 
p="%d\n"; 
 p++; 
 p++; 
 printf(p-2,300); 
} 

A. Compile time error B. 999 C. 298 D.300

Answer: 300
Explanation: The pointer points to % since it is incremented twice and again decremented by 2, it points to ‘%d\n’ and 300 is printed.

Q76. What is the output of this C code?

 void main() 
{ 
 char a[]="12345\0"; 
 int i=strlen(a); 
 printf("here in 3 %d\n",++i); 
} 

A. Compile time error B. here in 3 C. Null Value D. here in 3 6

Answer: here in 3 6
Explanation: The char array ‘a’ will hold the initialized string, whose length will be counted from 0 to the null character. Hence the ‘I’ will hold the value equal to 5, after the pre-increment in the printf statement, the 6 will be printed.

Q77. What is the output of this C code?

void main() 
{ 
 int i=i++,j=j++,k=k++; 
printf(“%d%d%d”,i,j,k); 
}

A. Compile time error B. Infinite C. Garbage D.1000

Answer: Garbage values.
Explanation: Expressions such as i = i++ are valid statements. The i, j, and k are automatic variables and so they contain some garbage value. Garbage in is garbage out (GIGO).

Q78. What is the default return type if it is not specified in the function definition?
A. void B. int C. double D. short int
Answer: Option B
Explanation: Theory Concept

Q79. 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: Option D
Explanation: Since only underscore and no other special character is allowed in a variable
name, it results in an error.

Q80. A variable declared in a function can be used in main?
A. True B. False C. True if it is declared static D. None of the mentioned.
Answer: Option B
Explanation: Since the scope of the variable declared within a function is restricted only within
that function.

Q81. A program that has no command-line arguments will have argc _________
a) Zero b) Negative
c) One d) Two
Answer: Option c
Explanation: Theory Concept

Q82. What is the index of the last argument in command-line arguments?
a) argc – 2 b) argc + 1
c) argc d) argc – 1
Answer: Option d
Explanation: Theory Concept

Q83. The size of a union is determined by the size of the __________
a) First member in the union
b) Last member in the union
c) Biggest member in the union
d) Sum of the sizes of all members
Answer: Option C
Explanation: Theory Concept

Q84. Members of a union are accessed as________________
a) union-name.member b) union-pointer->member
c) both union-name.member & union-pointer->member d) none of the mentioned
Answer: Option D
Explanation: Theory Concept

Q85. The function ____ obtains a block of memory dynamically.
a) calloc b) malloc
c) both calloc & malloc d) free
Answer: Option c
Explanation: The function calloc and malloc obtains a block of memory dynamically.

Q86. void * malloc(size_t n) returns?
a) Pointer to n bytes of uninitialized storage
b) NULL if the request can be satisfied
c) Nothing
d) None of the mentioned
Answer: Option A
Explanation: None.

Q87. calloc() returns storage that is initialized to.
a) Zero b) Null
c) Nothing d) One
Answer: Option a
Explanation: Theory Concept

Q88. In function free(p), p is a _______
a) int b) pointer returned by malloc()
c) pointer returned by calloc() d) pointer returned by malloc() & calloc()
Answer: Option D
Explanation: Theory Concept

Q89. Memory allocation using malloc() is done in _________
a) Static area b) Stack area
c) Heap area d) Both Stack & Heap area
Answer: Option C
Explanation: Theory Concept.

Q90. Why do we write (int *) before malloc?

int *ip = (int *)malloc(sizeof(int));

a) It is for the syntax correctness b) It is for the type-casting
c) It is to inform malloc function about the data-type expected d) None of the mentioned
Answer: Option B
Explanation: We write int* before malloc for typecasting

Q91. Which of the following is used during memory deallocation in C?
a) remove(p); b) delete(p);
c) free(p); d) terminate(p);
Answer: Option C
Explanation: Theory Concept.

Q92. Which of the following fopen() statements are illegal?
a) fp = fopen(“abc.txt”, “r”);
b) fp = fopen(“/home/user1/abc.txt”, “w”);
c) fp = fopen(“abc”, “w”);
d) none of the mentioned
Answer: Option D
Explanation: Theory Concept.

Q93. What does the following segment of C code do?

fprintf(fp, "Copying!");

a) It writes “Copying!” into the file pointed by fp
b) It reads “Copying!” from the file and prints on display
c) It writes as well as reads “Copying!” to and from the file and prints it
d) None of the mentioned
Answer: Option A
Explanation: It writes “Copying!” into the file pointed by fp

Q94. What is the FILE reserved word?
a) A structure tag declared in stdio.h b) One of the basic data types in c
c) Pointer to the structure defined in stdio.h d) It is a type name defined in stdio.h
Answer: Option D
Explanation: Theory Concept

Q95. stdout, stdin and stderr are ________
a) File pointers b) File descriptors
c) Streams d) Structure
Answer: Option A
Explanation: These all are file pointers.

Q96. Which of the following statements about stdout and stderr are true?
a) Same b) Both connected to screen always
c) Both connected to screen by default d) stdout is line-buffered but stderr is unbuffered
Answer: Option C
Explanation: Both stdout and stderr are connected screens by default.

Q97. What is the output of this C code?

void main() 
{ 
 static int i=i++, j=j++, k=k++; 
printf(“i = %d j = %d k = %d”, i, j, k); 
} 

A. Compile time error B. 0 1 0 C. Garbage D. 1 1 1

Answer: i = 1 j = 1 k = 1
Explanation: Since static variables are initialized to zero by default. Run Program Here

Q98. What is the output of this C code?

main() 
{ 
 unsigned int i=65000; 
 while(i++!=0); 
 printf("%d",i); 
} 

A. Compile time error B. Infinite C. 0 D.1

Answer: 1
Explanation: Note the semicolon after the while statement. When the value of I becomes 0 it comes out of the while loop. Due to post-increment on i the value of i while printing is 1. Check Code Here

Q99. What is the output of this C code?

main() 
{ 
char *p = “ayqm”; 
char c; 
c = ++*p++; 
printf(“%c”,c); 
}

A. Compile time error B. a C. b D. c

Answer: b
Explanation: There is no difference between the expression ++(p++) and ++p++. Parenthesis just works as a visual clue for the reader to see which expression is first evaluated. Check Code Here

Q100. What is the output of this C code?

main() 
{ 
int i=5; 
printf(“%d”,i=++i ==6); 
} 

A. 1 B. Infinite C. Garbage D.0

Answer: 1
Explanation: The expression can be treated as i = (++i==6), because == is of higher
precedence than = operator. In the inner expression, ++i is equal to 6 yielding true(1). Hence the result. Check output Here.

Conclusion

Hope you learned something from this post on 100 multiple choice questions in c Programming. Happy Coding!

Leave a Comment

Your email address will not be published. Required fields are marked *