C Interview Questions and Answers
1) How can we construct an increment statement or decrement statement in C?
Answer: We can do this in two different ways. 1) By using the increment operator ++ and decrement operator. For example, the statement “i++” means to increment the value of x by 1. Likewise, the statement “x –” means to decrement the value of x by 1. 2) The 2nd way of writing increment statements is to use the conventional + plus sign or minus sign. In the case of “i++, another way to write it is “i = i +1.
2) List the different storage class specifiers in C?
Answer: static, auto, extern, register
3) Some Programmers debug their programs by placing comment symbols on some of the codes instead of deleting it. How does this aid in debugging?
Answer: Using comment symbols “/* */ ” in a code, also called as commenting out, is a way of segregate some codes that you think maybe causing errors in the code, without deleting the program. The aim is that if the code is in fact correct, we can simply remove the comment symbols and continue on. It also saves you time and effort on having to retype the codes if you have deleted it in the first place.
4) What is call by value and call by reference in C Programming language?
We can pass value to function by two different ways: call by value and call by reference. In case of call by value, a copy of value is passed to the function, so original value is not modified in the call by value. But in case of call by reference, an address of value is passed to the function, so original value is modified in the call by reference.
5) How can we replace the following statement by using WHILE Loop?
for (x=1; x<=100; x++)
printf ("%d
", x *x );
Answer:
x=1;
while (x<=100)
{
printf ("%d
", x * x);
x++;
}
6) Name the different functions are used for dynamic memory allocation in C Program?
Answer:
malloc(),calloc(),realloc(),free()
7) Explain about spaghetti programming?
Answer: Spaghetti programming refers to programs that tend to get tangled and overlapped throughout the codes. This unorganized approach to coding is usually attributed to lack of experience on the part of the programmer. Spaghetti coding makes a program complex and analysing the codes difficult, and so must be avoided as much as possible.
8) Write the programming code to swap two numbers without using third variable?
int x=10, y=20;
printf("Before swap x=%d y=%d",x,y);
y=x-y; &nb x=x-y; printf( 9) In C program, how we can insert quote characters (‘ and ”) into the output screen? Answer: This is a common problem for freshers/beginners because quotes are normally part of a “printf” statement in program. If we want to insert the quote character as part of the output, use the format specifiers , and ” (for double quote) , ’ (for single quote). 10) Differentiate between the = symbol and == symbol? Answer: The = symbol is 11) For what purpose we use a ‘