C programming questions for interview

In this lecture, we are going to discuss basic C programming questions for interviews which will help you in your preparation for c language and also be used in your college exams as well as in competitive exams.

C programming questions for interview

Module 1: Constants, Variables, Data-types, Operators and Expression

Q.1 What is a Variable?

Answer: It is a symbolic name for the memory location in which the value is stored.

Q.2 What are trigraph characters? How they are useful?

Answer: ANSI C introduces the concept of “trigraph” sequences to provide a way to enter certain characters that are not available on some computers. Each trigraph sequence consists of three characters (two question marks followed by another character). For example, if a keyboard does not support square brackets, we can still use them in the program using a trigraph ?? (and??).

Q.3 State four basic data types. How could we extend the range of values they represent?


The four basic data types are

  • Char
  • int
  • float
  • double

Using short, long, unsigned, and signed keywords, we can extend or change the range of values they represent.

Q4. What is an unsigned integer constant? What is the significance of declaring a constant unsigned?

Answer: An unsigned integer constant requires 16 bits, and its range is 0 to 65535. When in our application, the value of the variable is never going to be negative, we can use an unsigned Integer constant, to extend its range.

Q5. Describe the characteristics and purpose of escape sequence characters.

Answer: C supports some special backslash character constants that are used in output functions. For example, the symbol ‘n’ stands for a new-line character. Note that each one of them represents one character, although they consist of two characters. These character combinations are known as escape sequences.

Q6. What is a variable and what is meant by the “value” of a variable?

Answer: A variable is a data name that may be used to store a data value. Unlike constants that remain unchanged during the execution of a program, a variable may take different values at different times during execution.

For example, int year=1999; where ‘year’ is a variable and 1999 is its value. The value of variable ‘year’ can be changed to 2000 using the statement year=2000;

Q7. How do variables and symbolic names differ?

Answer: define MAX 10; / MAX is Symbolic Name */

int amount=999; /* amount is Variable Name */

The value of a variable can be changed during the execution of the program, while the value of the symbolic name can not be altered and remains the same throughout the program

Q8. State the difference between the declaration of a variable and the definition of a symbolic name.

Answer: Symbolic names are normally defined outside of any function, i.e. they are global to all functions, where as variable are defined inside the function (except global variables).

Definition of symbolic name => #define TOTAL 10

Declaration of a variable => int total=10;

Q9. What is initialization? Why it is important?

Answer: Initialization is a process of assigning a value to a variable at the time of declaration. When we know, in advance, the first value of a variable, we can initialize that value for the variable.

Example: int x=10; /* Declaration & Initialization of variable x */

Q10. What are the qualifiers that an int can have at a time?

Answer: An int can have two qualifiers at a time.


  1. unsigned short int x, signed long int x,
  2. unsigned long int x etc.

Q.11 What are the enumeration variables? How are they declared? What is the advantage of using them in a program?

Answer: enum identifier { value1, value2, value3,… , valueN}

The “identifier” is a user-defined enumerated data type that can be used to declare variables that can have one of the values (enumerated constants) enclosed within braces. After this definition, we can declare a variable to be of this “new” type as follows:

enum day {Sun, Mon, Tue, Wed, Thu, Fri, Sat};

Declaration of a variable of enum type is as follows: enum day today;

Assigning a value to an enum type variable is as follows: today = Mon;

The compiler automatically assigns integer digits beginning with 0 to all enumerated constants. In the above example: Sun = 0, Mon = 1, …, Sat = 6.

Mainly, enum variables are used when they have fixed numbers of values.

Q.12 Describe the purpose of the qualifiers “const” and “volatile”.

Answer: The “Const” qualifier is used to give a value to a variable, which should remain constant during execution of a program, For example. const int total = 100;

“Const” tells the compiler that the value of int variable total must not be modified by the program. However, it can be used on the right-hand side of the assignment statement.

The “volatile” qualifier tells the compiler that a variable’s value may be changed at any time by some external source. For example, volatile int date; The value of date may be altered by some external factors even if it does not appear on the left-hand side of an assignment statement.

Q13. When dealing with small or very large numbers, what step would you take to improve the accuracy of the calculation?


First: we have to find out the type of value to be stored. For example, integer, real(float). Jouble, long, etc.

Second: we have to find out the approximate largest value to be stored in the variable. According to the answer to the above two points, we can decide the data type of the variable from numerical values.

Q15. What is the form of an assignment statement?

Answer: variable = expression (or constant)

Q 16. What are the rules for naming the variables?

Answer: They must begin with a letter (including the underscore), may contain only letters and digits, may not include any special characters, may not be a keyword and the first eight characters must be unique.

Q 17. How many variables may appear on the left of the equal sign in the assignment expression?

Answer: Only one.

Q 18. Classify briefly, operators.


  1. Arithmetic (+,-,*,/,%)
  2. Relational (<, >, <=, >=, ==, !=)
  3. Logical (&&, II, 1)
  4. Assignment (=, +, -, /=, =,%=)
  5. Increment/decrement operator (++, -)
  6. Conditional operator (?:)
  7. Bit-wise operator (&, >>, <<, ^, -, 1)
  8. Special Operator (comma operator, sizeof, pointer operator (& and”), member selection operator (. and ->)

Q 19. Distinguish between binary and unary minus.


Binary minus: Example A =B-C.

Unary minus: Example A = -B

The binary minus has an operand before and after the minus sign and is used for subtraction. The unary minus has only one operand (to its right) and serves to convert a positive value to its negative and vice-versa.

Q 20. What is meant by truncation?

Answer: It is the rounding down of the effect achieved, among other times when an integer is divided by another integer and the resultant fraction part is chopped off.

Q21. What is the effect of dividing an integer by a real(float) quantity? Also, what is this effect called?

Answer: The integer is temporarily converted to its floating-point equivalent before the calculation is performed. The automatic operation is known as implicit conversion.

Q 22. State two different ways to multiply the variable x and y, placing the result in x.

Answer: (1) x=x*y; (2) x*=y

Q 23. What is the difference between a pre-decrement and a post-decrement operation?

Answer: Pre-decrement operation, such as -a, decrements the value of a by 1 before a is used in a computation, while a post-decrement operation like a-, uses the current value of a in a calculation and then decrements it.

Module 2: Decision Making And Branching

Q 1. What statement should precede every scanf statement and why?

Answer: A print, advising the user that input is required, and specifying of what type it should be.

Q 2. What is a nested if statement?

Answer: An if statement in which the if clause or the else clause contains another if statement.

Q 3. What is the difference between two operators = and ==?

Answer: The single equal sign means assignment, whereas the double equal sign is a relational operator used for testing purposes.

Q 4. What integer values are equivalent to “true” and “false”?

Answer: For True = 1 and for False = 0.

Q 5. state whether the following statements are true or false.

  1. one if can have more than one else clause.
    • True. (in the if-else if ladder there is more than one else clause with one if.)
  2. A switch statement can always be replaced by a series of is-else statements.
    • False. (But can be replaced by if-else if ladder.)
  3. A switch expression can be of any type.
    • False. (It can not be of float type.)
  4. A program stops its execution when a break statement is encountered.
    • False. (It breaks the loop in which it encounters a break statement. and executes the remaining statement after the loop.)

Q 6. In what ways does a switch statement differ from an if statement?

Answer: Logically, each program written using an if statement, can be implemented using a switch statement, and vice versa. But in the if statement, when a number of alternatives increases, the program increases dramatically. The program becomes difficult to read and follow. The use of a switch makes the program easy to read, write, and understand.

Hello friends, my name is Trupal Bhavsar, I am the Writer and Founder of this blog. I am Electronics Engineer(2014 pass out), Currently working as Junior Telecom Officer(B.S.N.L.) also I do Project Development, PCB designing and Teaching of Electronics Subjects.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

telegram logo Join Our Telegram Group!