#1: Which is 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: b
Explanation: space, comma and $ cannot be used in a variable
name.
#2: What is the output of this C code?
#include
int main()
{
printf("Hello
World! %d \n", x);
return 0;
}
a) Hello World! x;
b) Hello World! followed by a junk value
c) Compile time error
d) Hello World!
Explanation: It results in an error since x is used without
declaring the variable x.
#3: What will happen if the below program is executed?
#include
int main()
{
int main = 3;
printf("%d", main);
return 0;
}
a) It will cause a compile-time error
b) It will cause a run-time error
c) It will run without any error and prints 3
d) It will experience infinite looping
Answer: c
Explanation: A C program can have same function name and
same variable name.
#4: What is the output of this C code?
#include
int main()
{
char chr;
chr = 128;
printf("%d\n", chr);
return 0;
}
a) 128
b) -128
c) Depends on the compiler
d) None of the mention
Answer: b
Explanation: signed char will be a negative number.
#5: What is the output of this C code?
#include
int main()
{
char *p[1] =
{"hello"};
printf("%s", (p)[0]);
return 0;
}
a) Compile time error
b) Undefined behaviour
c) hello
d) None of the mentioned
Answer: c
Explanation: None
#6: What is the output of this C code?
#include
int main()
{
printf("crazyfor\code\n");
return 0;
}
a) crazyforcode
b) crazyforcode
c) codeyfor
d) crazyfor
Answer: c
Explanation: r is carriage return and moves the cursor back.
sanfo is replaced by class
Thanks for sharing this C interview questions. It is really helpful. Continue sharing more like this.
ReplyDeleteC++ Training | C Language Training | C++ programming course
I didn’t understand the explanation given for 6 th question .! And I guess the answer was not option c .. instead it is A. The output will be crazyforcode
ReplyDeleteNice and very helpful article....
ReplyDeleteSwitch Case in C examples
if-else in C with examples
betmatik
ReplyDeletekralbet
betpark
tipobet
slot siteleri
kibris bahis siteleri
poker siteleri
bonus veren siteler
mobil ödeme bahis
HK7N0
<a href="https://
ReplyDelete