C Programming Basics – Interview Questions

1. What is Token?

A token is a building block of a program. A C program consists of various tokens and a token is either a keyword, an identifier, a constant, a string literal, or a symbol.

2. What is Keyword?

Keywords are special reserved words associated with some meaning.

3. What is keyword auto for?

By default, every local variable of the function is automatic (auto). In the below function both the variables „x‟ and „y‟ are automatic variables.

void fun()
{
int x,
auto int q;
}

4. What are main characteristics of C language?

C is a procedural language. The main features of C language include low-level access to memory, simple set of keywords, and clean style. These features make it suitable for system programming like operating system or compiler development.

5. What are reserved words?

Reserved words are words that are part of the standard C language library.This means that reserved words have special meaning and therefore cannot be used for purposes other than what it is originally intended for. Examples of reserved words are float, default, and return.

6. What are the types of C tokens?

C tokens are of six types. They are,

Keywords              (eg: int, while),
Identifiers           (eg: main, total),
Constants             (eg: 10, 20),
Strings               (eg: “total”, “hello”),
Special symbols       (eg: (), {}),
Operators             (eg: +, /,-,*)

7. What is the use of printf() and scanf()?

printf(): The printf() function is used to print the integer, character, float and string values on to the screen.

Following are the format specifier:

  • %d: It is a format specifier used to print an integer value.
  • %s: It is a format specifier used to print a string.
  • %c: It is a format specifier used to display a character value.
  • %f: It is a format specifier used to display a floating point value.

scanf(): The scanf() function is used to take input from the user.

8. What is data types in C?

  • Data types in C language are defined as the data storage format that a variable
  • can store a data to perform a specific operation.
  • Data types are used to define a variable before to use in a program.
  • Size of variable, constant and array are determined by data types.

9. What is typecasting?

The typecasting is a process of converting one data type into another is known as typecasting. If we want to store the floating type value to an int type, then we will convert the data type into another data type explicitly.

(type-name) expression

10. What is the difference between variable declaration and variable definition?

Declaration associates type to the variable whereas definition gives the value to the variable.

11. What are global variable and how do you declare them?

Global variables are variables that can be accessed and manipulated anywhere in the program. To make a variable global, place the variable declaration on the upper portion of the program, just after the pre_processor directives section.

12. What is local variable in C?

  • The variables which are having scope/life only within the function are called local variables.
  • These variables are declared within the function and can‟t be accessed outside the function.

13. What is constant in C?

  • Constants refer to fixed values. They are also called as literals.
  • C Constants are also like normal variables. But, only difference is, constant values can‟t be modified by the program once they are defined. Constants may be belonging to any of the data type.

14. What are the types of constants in C?

  • Integer constants
  • Real or Floating point constants
  • Octal & Hexadecimal constants
  • Character constants
  • String constants
  • Backslash character constants

15. What is the difference between = and == symbol?

The = symbol is often used in mathematical operations. It is used to assign a value to a given variable. On the other hand, the == symbol, also known as “equal to” or “equivalent to”, is a relational operator that is used to compare two values.

16. Describe the order of precedence with regards of operator in C.

Order of precedence determines which operation must first take place in an operation statement or conditional statement. On the top most level of precedence are the unary operators !, +, – and &. It is followed by the regular mathematical operators (*, / and modulus % first, followed by + and -). Next in line are the relational operators <, = and >. This is then followed by the two equality operators == and !=. The logical operators && and || are next evaluated. On the last level is the assignment operator =.

17. What is the difference between pre-increment operator and post increment operator?

  • Pre increment operator is used to increment variable value by 1 before assigning the value to the variable.
  • Post increment operator is used to increment variable value by 1 after assigning the value to the variable.

18. What are all decision control statement in C?

There are 3 types of decision making control statements in C language. They are,

1. if statements
2. if else statements
3. nested if statements

19. What will happen if break statement is not used in switch case in C?

  • Switch case statements are used to execute only specific case statements based on the switch expression.
  • If we do not use break statement at the end of each case, program will execute all consecutive case statements until it finds next break statement or till the end of switch case block.

20. What is nested loop?

A nested loop is a loop that runs within another loop. Put it in another sense, you have an inner loop that is inside an outer loop. In this scenario, the inner loop is performed a number of times as specified by the outer loop. For each turn on the outer loop, the inner loop is first performed.

21. What is the difference between while and do…while loop in C?

  • While loop is executed only when given condition is true.
  • Whereas, do-while loop is executed for first time irrespective of the condition. After executing while loop for first time, then condition is checked.
Related Post