
Preparing for a C programming interview? Here are some of the most frequently asked C programming questions, complete with answers and explanations to help you ace your technical interview.
Question: Is there any difference in the following declarations?
int myfun(int arr[]);
int myfun(arr[20]);
Answer: Option 1
Explanation: Yes, we must specify the data type of the parameter when declaring a function.
extern for Variables Across FilesQuestion: Suppose a program is divided into three files f1, f2, and f3, and a variable is defined in f1 but used in f2 and f3. Would we need the extern declaration in f2 and f3?
Answer: Option 1
Explanation: To use a variable f1 in FILE2.C and FILE3.C, declare it as extern int f1; in those files.
Question: Can a global variable be available to only some functions while being restricted to others?
Answer: Option 2
Explanation: To restrict access, define it locally in main() and pass it to necessary functions.
Question: Can a global variable have multiple declarations but only one definition?
Answer: Option 1
Explanation: Yes, extern should be used in multiple declarations, but only one definition is allowed.
Question: Can a function have multiple declarations but only one definition?
Answer: Option 1
Explanation: Yes, but all declarations must be identical.
Question: How many times will the while loop execute if short int is 2 bytes wide?
#include<stdio.h>
int main() {
int j = 1;
while(j <= 255) {
printf("%c %d\n", j, j);
j++;
}
return 0;
}
Answer: Option 2
Explanation: The while(j <= 255) loop runs exactly 255 times. The short int size does not affect loop execution.
Question: Which of the following is NOT a logical operator?
&&&||!Answer: Option 1
Explanation: & is a bitwise AND operator, not a logical operator.
Question: What is the correct order of mathematical operators in programming?
Answer: Option 2
Explanation: The correct order follows BODMAS (Brackets, Orders, Division, Multiplication, Addition, Subtraction).
Question: Which of the following data types cannot be used in a switch-case statement?
Answer: Option 3
Explanation: switch-case works only with int, char, and enum, not float.
Question: Point out the error, if any, in the following C program.
#include<stdio.h>
int main() {
int i = 1;
switch(i) {
printf("This is a C program.");
case 1:
printf("Case1");
break;
case 2:
printf("Case2");
break;
}
return 0;
}
printf statement after switch statementAnswer: Option 3
Explanation: switch(i) evaluates as switch(1), so case 1 executes, printing “Case1”. The first printf is ignored.
These questions cover fundamental C programming interview topics, including functions, global variables, operators, loops, and control structures. Mastering these concepts will enhance your preparation for technical interviews and coding assessments.
Stay tuned for more C programming insights and practice questions!