Commonly Asked C Programming Interview Questions | Set 1
1. What is C language?
Ans: C language is a structure/procedure oriented, middle level programming language developed at Bell Laboratories in 1972 by Dennis Ritchie.
- C language was invented for implementing UNIX operating system.
- In 1978, Dennis Ritchie and Brian Kernighan published the first edition “The C Programming Language”.
- Also, C language is an ANSI/ISO standard and powerful programming language for developing real time applications
2. What are different storage class specifiers in C?
Ans: auto, register, static, extern
3. What is scope of a variable? How are variables scoped in C?
Ans: Scope of a variable is the part of the program where the variable may directly be accessible. In C, all identifiers are lexically (or statically) scoped.
4. What are the key features in the C programming language?
Ans: Features are as follows:
- Portability: It is a platform-independent language.
- Modularity: Possibility to break down large programs into small modules.
- Flexibility: The possibility of a programmer to control the language.
- Speed: C comes with support for system programming and hence it compiles and executes with high speed when compared with other high-level languages.
- Extensibility: Possibility to add new features by the programmer.
5. What are the basic data types associated with C?
- Int – Represent the number (integer)
- Float – Number with a fraction part.
- Double – Double-precision floating-point value
- Char – Single character
- Void – Special purpose type without any value.
6. What is the use of printf() and scanf() functions?
Ans: printf(): The printf() function is used to print the integer, character, float and string values on to the screen.
scanf() The scanf() function is used to take input from the user.
7. What is the description for syntax errors?
Ans: The mistakes/errors that occur while creating a program are called syntax errors. Misspelled commands or incorrect case commands, an incorrect number of parameters in calling method /function, data type mismatches can be identified as common examples for syntax errors.
8. When should we use pointers in a C program?
Ans: 1. To get address of a variable
2. For achieving pass by reference in C: Pointers allow different functions to share and modify their local variables.
3. To pass large structures so that complete copy of the structure can be avoided.
4. To implement “linked” data structures like linked lists and binary trees.
9. What are static variables and functions?
Ans: The variables and functions that are declared using the keyword Static are considered as Static Variable and Static Functions. The variables declared using Static keyword will have their scope restricted to the function in which they are declared.
10. Differentiate between calloc() and malloc()
Ans: calloc() and malloc() are memory dynamic memory allocating functions. The only difference between them is that calloc() will load all the assigned memory locations with value 0 but malloc() will not.