C Inteview Questions – Introduction
1. [Asked in Infosys] What is the C programming language?
Answer:
C is a general-purpose, procedural programming language developed by Dennis Ritchie at Bell Labs in 1972. It is widely used for system programming, embedded systems, and application development.
Key Features:
- Simple and efficient – Uses a structured approach.
- Fast execution – Close to assembly language.
- Portable – Runs on various platforms.
- Rich library support – Standard library functions.
Example Use Case:
- Operating Systems (Linux, Windows kernels are written in C).
2. [Asked in TCS] Why is C called a procedural language?
Answer:
C is called a procedural language because it follows a step-by-step approach where programs are structured into procedures (functions).
Characteristics of Procedural Programming:
- Uses functions to break down problems.
- Sequential execution of statements.
- Modular approach for better maintainability.
Example:
#include <stdio.h>
void greet() {
printf("Hello, World!");
}
int main() {
greet(); // Function call
return 0;
}
Here, greet() is a procedure (function) used to print a message.
3. [Asked in Cognizant] What are the main applications of C programming?
Answer:
C is widely used in system and application development due to its speed and efficiency.
Real-World Applications:
- Operating Systems – Linux, Windows, Unix.
- Embedded Systems – Microcontrollers, IoT devices.
- Game Development – Graphics engines.
- Database Systems – MySQL, PostgreSQL.
- Compiler Development – GCC, Clang.
Example:
- The Python interpreter (CPython) is written in C.
4. [Asked in Wipro] What is the structure of a C program?
Answer:
A basic C program structure consists of:
Components of a C program:
- Preprocessor Directives (
#include <stdio.h>) - Global Declarations
- Main Function (
int main()) - Statements and Logic
- Return Statement (
return 0;)
Example:
#include <stdio.h> // Preprocessor Directive
int main() { // Main Function
printf("Hello, C!"); // Statement
return 0; // Return Statement
}
5. [Asked in IBM] What is the difference between C and C++?
Answer:
| Feature | C | C++ |
|---|---|---|
| Paradigm | Procedural | Object-Oriented + Procedural |
| Data Security | No encapsulation | Supports encapsulation (classes) |
| Function Overloading | Not supported | Supported |
| Memory Management | Uses malloc() and free() | Uses new and delete |
Example:
- C is used for OS kernels, while C++ is used for game development.
6. [Asked in Deloitte] What are the basic data types in C?
Answer:
C has four primary data types:
| Type | Size | Example |
|---|---|---|
| int | 4 bytes | int a = 10; |
| float | 4 bytes | float pi = 3.14; |
| char | 1 byte | char c = 'A'; |
| double | 8 bytes | double d = 9.8765; |
Example:
int num = 100;
float pi = 3.14;
char letter = 'C';
double largeValue = 9876.543;
7. [Asked in Amazon] What are the key differences between printf() and scanf()?
Answer:
| Feature | printf() | scanf() |
|---|---|---|
| Purpose | Outputs data | Takes user input |
| Format Specifiers | %d, %f, %s, %c | %d, %f, %s, %c |
| Return Type | Number of characters printed | Number of inputs read |
Example:
#include <stdio.h>
int main() {
int age;
printf("Enter your age: ");
scanf("%d", &age);
printf("You are %d years old", age);
return 0;
}
8. [Asked in Microsoft] What is a pointer in C, and why is it important?
Answer:
A pointer is a variable that stores the memory address of another variable.
Importance of Pointers:
- Efficient memory management.
- Used in data structures (linked lists, trees, etc.).
- Pass-by-reference in functions.
Example:
#include <stdio.h>
int main() {
int num = 10;
int *ptr = # // Pointer stores the address of num
printf("Value: %d, Address: %p", *ptr, ptr);
return 0;
}
Output:
Value: 10, Address: 0x7ffee5b7d3a4
9. [Asked in Google] What is the difference between while and do-while loops?
Answer:
| Feature | while Loop | do-while Loop |
|---|---|---|
| Condition Check | Before execution | After execution |
| Execution Guarantee | May not execute | Executes at least once |
Example:
// while loop
int i = 0;
while (i < 3) {
printf("Hello ");
i++;
}
// do-while loop
int j = 0;
do {
printf("World ");
j++;
} while (j < 3);
10. [Asked in Flipkart] What is a typedef in C?
Answer:typedef is used to create user-defined names for existing data types.
Benefits:
- Improves readability.
- Simplifies complex struct declarations.
Example:
typedef unsigned int UI;
UI age = 25; // Now UI is an alias for unsigned int
