Top 45 C programming interview questions and answers

16) What are local variables in C Programming?

Local variables are the ones declared inside a function or a block (a block can be any number of statements inside if, for, switch or function). Local variables are not known outside where they are declared.

17) What are global variables in C Programming?

The global variables are declared before the main function and they are accessible from anywhere in the program. In other words, global variables are known to every function.

18) Describe different operators in C programming

In C programming, we have:

  1. Arithmetic operators to perform arithmetic or mathematical operations which may include addition, subtraction, etc.
  2. Logical operators to compare two conditions. The result is always of Boolean type.
  3. Relational operators to compare values of operands.
  4. Assignment operator to assign values to variables (identifiers).
  5. Compound assignment operators to combine assignment and arithmetic operator to perform some arithmetic operations.
19) What is the use of logical operators in C programming?

In C programming, we have:

  1. Logical And operator (&&)
  2. Logical OR operator (||)
  3. Logical not operator

Logical operators are used to combine conditions and result is of Boolean type either true or false.

20) What is difference between for and while loops?

for loop is used when you know that how many times the loop has to be executed. while loop is used when the number of iterations are not known.


21) What is the main difference between while and do while loop?

In while loop if the condition is false the control is not entered into the body of while loop. In do while loop the condition comes after the body of the loop so the body will be executed at least once.

22) What are unary operators in C programming?

Unary operators are the one that operates on one operand only for example increment and decrement operators to make an increment and decrement of one in the value of variable respectively.

23) What is the syntax of switch statement?

In switch statement we have switch key word and a condition the result of which is compared with a number of cases. At the end we have default part which is executed when all cases are false:

case 1:
case 2:
canse N:
//N statements
24) What difference is between continue and break statements?

continue statement skips the current iteration of the loop on the basis of a condition and break statement breaks the control making the control move outside the body of the loop on the basis of condition.

25) What is the main difference between switch and if statement?

Both switch and if statements have multiple choices of which only one is executed. But in switch you cannot check range of values.

26) What is the use of ternary operator?

Ternary operator works with three operands. Ternary operator is a decision making construct. The first operand in ternary is the condition. If the condition is true second operand is executed else third operand is executed. Instead of if else, ternary operator can also be used.

27) What is an auto variable?

An auto variable is a local variable. When you declare a variable as automatic it will be allocated memory at the beginning of the execution of the program and memory will be de allocated when the execution is done.

28) What are the storage classes in C?

Storage classes specify how the variables will be stored in memory and where the variables are known in the program (scope of variables). Storage classes in C are:

  1. Local variables
  2. Global variables
  3. Register variables
  4. Static variables
  5. Automatic variables
29) What is the difference between an auto and a register variable?

An auto variable is a regular variable which is allocated memory when it is created and memory is de allocated when execution of program ends so this variable is destroyed. On the other hand a register keyword is used to create a register variable which will be stored in register in RAM. Register variables are fast and are accessed directly by the compiler.

30) What is the use of static keyword?

When you create a static variable, the value of this variable will remain constant throughout the program. These variables are defined at the beginning of the program. Static variables cannot be destroyed.


« 1 2 3 »  


Popular Posts


Founded in 2016, Tech Study passionately delivers stylish and dynamic innovative information to programmer & technology lovers.