C Programming Interview Questions and Answers
1. What is C language?
C is a procedural programming language developed in the 1970s by Dennis Ritchie. It is known for
system-level programming, speed, and portability.
2. Features of C:
- Fast and efficient
- Rich library of built-in functions
- Low-level and high-level features
- Structured and modular
- Portable
3. Compiler vs Interpreter:
Compiler: Translates whole code; faster execution; used in C, C++.
Interpreter: Line-by-line translation; slower; used in Python, JavaScript.
4. Structure of a C program:
#include <stdio.h>
int main() {
printf("Hello!");
return 0;
5. Keywords in C:
Reserved words like int, float, if, else, for, return.
6. Variables in C:
Named memory locations. Example: int age = 25;
7. Data Types:
- int: 2 or 4 bytes
- float: 4 bytes
- double: 8 bytes
- char: 1 byte
8. Operators:
Arithmetic, Relational, Logical, Bitwise, Assignment, Increment/Decrement
9. '=' vs '==':
= assigns value; == compares two values.
10. sizeof:
Returns size of a variable/data type.
11. Control Structures:
- if, else if, switch for condition checking
- for, while, do-while for loops
- break exits loop; continue skips iteration
12. Functions:
Reusable code blocks. Example:
int add(int a, int b) { return a + b; }
13. Call by value/reference:
Value: Original not affected. Reference: Original can change.
14. Recursion:
Function calling itself. Example: factorial.
15. Arrays:
Collection of same data type. Example: int arr[5];
16. Strings:
Char arrays ending with '\0'. Example: char name[] = "John";
17. scanf vs gets:
scanf stops at space; gets reads full line.
18. Pointers:
Stores address. Example: int *ptr = &a;
19. Structure vs Union:
Structure: Different types, individual memory. Union: Shared memory.
20. Dynamic Memory:
malloc, calloc, realloc allocate memory; free deallocates.
21. File Handling:
fopen("file.txt", "r"); Modes: "r", "w", "a", etc.
22. Typedef vs #define:
typedef creates alias; #define creates macros.
23. static vs extern:
static: Limited scope. extern: Global linkage.
24. Compile Time vs Run Time:
Compile time: Syntax check. Run time: Logic errors.