Explore topic-wise MCQs in C Interview.

This section includes 278 Mcqs, each offering curated multiple-choice questions to sharpen your C Interview knowledge and support exam preparation. Choose a topic below to get started.

151.

Longevity of a variable refers to

A. The duration for which the variable retains a given value during the execution of a program.
B. The portion of a program in which the variable may be visible.
C. Internal linkage of a variable.
D. External linkage of a variable.
Answer» B. The portion of a program in which the variable may be visible.
152.

Which variable has the longest scope in the following C code? #include int b; int main() { int c; return 0; } int a;

A. a
B. b
C. c
D. Both a and b
Answer» C. c
153.

Comment on the output of the following C code.#include int main() { int i; for (i = 0;i < 5; i++) int a = i; printf("%d", a); }

A. a is out of scope when printf is called
B. Redeclaration of a in same scope throws error
C. Syntax error in declaration of a
D. No errors, program will show the output 5
Answer» D. No errors, program will show the output 5
154.

What is the scope of a function?

A. Whole source file in which it is defined
B. From the point of declaration to the end of the file in which it is defined
C. Any source file in a program
D. From the point of declaration to the end of the file being compiled
Answer» E.
155.

What will be the output of the following C code (without linking the source file in which ary1 is defined)? #include int main() { extern ary1[]; printf("scope rules\n"); }

A. scope rules
B. Linking error due to undefined reference
C. Compile time error because size of array is not provided
D. Compile time error because datatype of array is not provided
Answer» B. Linking error due to undefined reference
156.

What is the scope of an external variable?

A. Whole source file in which it is defined
B. From the point of declaration to the end of the file in which it is defined
C. Any source file in a program
D. From the point of declaration to the end of the file being compiled
Answer» E.
157.

What will be the output of the following C code (after linking to source file having definition of ary1)? #include int main() { extern ary1[]; printf("%d\n", ary1[0]); }

A. Value of ary1[0];
B. Compile time error due to multiple definition
C. Compile time error because size of array is not provided
D. Compile time error because datatype of array is not provided
Answer» E.
158.

What will be the output of the following C code? #include int i; int main() { extern int i; if (i == 0) printf("scope rules\n"); }

A. scope rules
B. Compile time error due to multiple declaration
C. Compile time error due to not defining type in statement extern i
D. Nothing will be printed as value of i is not zero because i is an automatic variable
Answer» B. Compile time error due to multiple declaration
159.

What will be the output of the following C code? #include int *i; int main() { if (i == 0) printf("true\n"); return 0; }

A. true
B. true only if NULL value is 0
C. Compile time error
D. Nothing
Answer» C. Compile time error
160.

What will be the output of the following C code? #include int *i; int main() { if (i == NULL) printf("true\n"); return 0; }

A. true
B. true only if NULL value is 0
C. Compile time error
D. Nothing
Answer» B. true only if NULL value is 0
161.

Can variable i be accessed by functions in another source file? #include int i; int main() { printf("%d\n", i); }

A. Yes
B. No
C. Only if static keyword is used
D. Depends on the type of the variable
Answer» B. No
162.

What will be the output of the following C code? #include double i; int main() { printf("%g\n",i); return 0; }

A. 0
B. 0.000000
C. Garbage value
D. Depends on the compiler
Answer» B. 0.000000
163.

Which part of the program address space is p stored in the following C code? #include int *p; int main() { int i = 0; p = &i; return 0; }

A. Data segment
B. Code/text segment
C. Bss segment
D. Stack
Answer» D. Stack
164.

What will be the output of the following C code? #include int main() { printf("%d", d++); } int d = 10;

A. 9
B. 10
C. 11
D. Compile time error
Answer» E.
165.

Which part of the program address space is p stored in the following C code? #include int *p = NULL; int main() { int i = 0; p = &i; return 0; }

A. Code/text segment
B. Data segment
C. Bss segment
D. Stack
Answer» C. Bss segment
166.

What will be the output of the following C code? #include double var = 8; int main() { int var = 5; printf("%d", var); }

A. 5
B. 8
C. Compile time error due to wrong format identifier for double
D. Compile time error due to redeclaration of variable with same name
Answer» B. 8
167.

Which of the following is an external variable in the following C code? #include int func (int a) { int b; return b; } int main() { int c; func (c); } int d;

A. a
B. b
C. c
D. d
Answer» E.
168.

Global variables are ____________

A. External
B. Internal
C. Both External and Internal
D. None of the mentioned
Answer» B. Internal
169.

Functions in C are always _________

A. Internal
B. External
C. Both Internal and External
D. External and Internal are not valid terms for functions
Answer» C. Both Internal and External
170.

What will be the output of the following C code? #include int x; void main() { printf("%d", x); }

A. Junk value
B. Run time error
C. 0
D. Undefined
Answer» D. Undefined
171.

What will be the output of the following C code? #include int x = 5; void main() { int x = 3; printf("%d", x); { x = 4; } printf("%d", x); }

A. Run time error
B. 3 3
C. 3 5
D. 3 4
Answer» E.
172.

What will be the output of the following C code? #include int x = 5; void main() { int x = 3; printf("%d", x); { int x = 4; } printf("%d", x); }

A. 3 3
B. 3 4
C. 3 5
D. Run time error
Answer» B. 3 4
173.

What will be the output of the following C code? #include void main() { m(); printf("%d", x); } int x; void m() { x = 4; }

A. 4
B. Compile time error
C. 0
D. Undefined
Answer» C. 0
174.

An external variable is one:

A. Which is globally accessible by all functions
B. Which is declared outside the body of any function
C. Which resides in the memory till the end of a program
D. All of the above
Answer» E.
175.

What will be the output of the following C code? #include void main() { int x = 0; int *ptr = &5; printf("%p\n", ptr); }

A. 5
B. Address of 5
C. Nothing
D. Compile time error
Answer» E.
176.

Which is an indirection operator among the following?

A. &
B. *
C. ->
D. .
Answer» C. ->
177.

What will be the output of the following C code? #include void main() { int x = 0; int *ptr = &x; printf("%d\n", *ptr); }

A. Address of x
B. Junk value
C. 0
D. Run time error
Answer» D. Run time error
178.

What will be the output of the following C code? #include int x = 0; void main() { int *const ptr = &x; printf("%p\n", ptr); ptr++; printf("%p\n ", ptr); }

A. 0 1
B. Compile time error
C. 0xbfd605e8 0xbfd605ec
D. 0xbfd605e8 0xbfd605e8
Answer» C. 0xbfd605e8 0xbfd605ec
179.

What will be the output of the following C code? #include int x = 0; void main() { int *ptr = &x; printf("%p\n", ptr); x++; printf("%p\n ", ptr); }

A. Same address
B. Different address
C. Compile time error
D. Varies
Answer» B. Different address
180.

Which of the following does not initialize ptr to null (assuming variable declaration of a as int a=0;)?

A. int *ptr = &a;
B. int *ptr = &a – &a;
C. int *ptr = a – a;
D. All of the mentioned
Answer» B. int *ptr = &a – &a;
181.

Comment on the following C statement. const int *ptr;

A. You cannot change the value pointed by ptr
B. You cannot change the pointer ptr itself
C. You May or may not change the value pointed by ptr
D. You can change the pointer as well as the value pointed by it
Answer» B. You cannot change the pointer ptr itself
182.

What will be the output of the following C code? #include int main() { int *ptr, a = 10; ptr = &a; *ptr += 1; printf("%d,%d/n", *ptr, a); }

A. 10,10
B. 10,11
C. 11,10
D. 11,11
Answer» E.
183.

What will be the output of the following C code? #include int main() { int i = 10; void *p = &i; printf("%f\n", *(float*)p); return 0; }

A. Compile time error
B. Undefined behaviour
C. 10
D. 0.000000
Answer» E.
184.

What will be the output of the following C code? #include int main() { int i = 10; void *p = &i; printf("%d\n", (int)*p); return 0; }

A. Compile time error
B. Segmentation fault/runtime crash
C. 10
D. Undefined behaviour
Answer» B. Segmentation fault/runtime crash
185.

Comment on the following pointer declaration. int *ptr, p;

A. ptr is a pointer to integer, p is not
B. ptr and p, both are pointers to integer
C. ptr is a pointer to integer, p may or may not be
D. ptr and p both are not pointers to integer
Answer» B. ptr and p, both are pointers to integer
186.

What will be the output of the following C code? #include int *f(); int main() { int *p = f(); printf("%d\n", *p); } int *f() { int *j = (int*)malloc(sizeof(int)); *j = 10; return j; }

A. 10
B. Compile time error
C. Segmentation fault/runtime crash since pointer to local variable is returned
D. Undefined behaviour
Answer» B. Compile time error
187.

What will be the output of the program If the integer is 4bytes long? #include int main() { int ***r, **q, *p, i=8; p = &i; q = &p; r = &q; printf("%d, %d, %d\n", *p, **q, ***r); return 0; }

A. 8, 8, 8
B. 4000, 4002, 4004
C. 4000, 4004, 4008
D. 4000, 4008, 4016
Answer» B. 4000, 4002, 4004
188.

What will be the output of the program ? #include int main() { int x=30, *y, *z; y=&x; /* Assume address of x is 500 and integer is 4 byte size */ z=y; *y++=*z++; x++; printf("x=%d, y=%d, z=%d\n", x, y, z); return 0; }

A. x=31, y=502, z=502
B. x=31, y=500, z=500
C. x=31, y=498, z=498
D. x=31, y=504, z=504
Answer» E.
189.

What will be the output of the program ? #include int main() { char str[20] = "Hello"; char *const p=str; *p='M'; printf("%s\n", str); return 0; }

A. Mello
B. Hello
C. HMello
D. MHello
Answer» B. Hello
190.

What will be the output of the program ? #include int main() { int i=3, *j, k; j = &i; printf("%d\n", i**j*i+*j); return 0; }

A. 30
B. 27
C. 9
D. 3
Answer» B. 27
191.

What will be the output of the program ? #include int main() { static char *s[] = {"black", "white", "pink", "violet"}; char **ptr[] = {s+3, s+2, s+1, s}, ***p; p = ptr; ++p; printf("%s", **p+1); return 0; }

A. ink
B. ack
C. ite
D. let
Answer» B. ack
192.

How many loops are there in C

A. 2
B. 3
C. 4
D. 1
Answer» C. 4
193.

What will be the output of the following C code?#include int main() { char *p = NULL; char *q = 0; if (p) printf(" p "); else printf("nullp"); if (q) printf("q\n"); else printf(" nullq\n"); }

A. nullp nullq
B. Depends on the compiler
C. x nullq where x can be p or nullp depending on the value of NULL
D. p q
Answer» B. Depends on the compiler
194.

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» E.
195.

When C Language was invented?

A. 1970
B. 1972
C. 1978
D. 1979
Answer» C. 1978
196.

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» B. False
197.

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» E.
198.

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» E.
199.

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» B. if (func1 (a)){}
200.

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» C. true, 10