1. What is C programming, and why is it important?
Answer: C is a general-purpose, procedural programming language developed by
Dennis Ritchie in 1972. It is essential because:
It provides low-level memory access.
It forms the foundation of modern programming languages like C++ and
Java.
It is widely used in system programming, embedded systems, and
performance-critical applications.
2. How do you set up a C development environment?
Answer: To set up a C environment:
1. Install a text editor (e.g., VS Code, Sublime Text).
2. Install a C compiler like GCC or Clang.
3. Write a program in a .c file.
4. Compile using the command: gcc filename.c.
5. Run the compiled program.
3. What is the structure of a C program?
Answer: A basic C program consists of:
Preprocessor directives (e.g., #include <stdio.h>)
main() function: The program's entry point
Statements and function calls
Example:
#include <stdio.h>
, int main() {
printf("Hello, World!\n");
return 0;
}
4. What are the different data types in C?
Answer: C has several data types:
Basic types: int, float, double, char
Derived types: Arrays, Pointers, Structures, Unions
Void: Represents no value
5. What are pointers, and why are they used?
Answer: Pointers store the memory address of another variable. They are used
for:
Dynamic memory allocation
Efficient array and structure handling
Passing arguments by reference
Example:
int x = 10;
int* ptr = &x;
printf("Value: %d, Address: %p\n", *ptr, ptr);
6. How does a for loop work in C?
Answer: A for loop executes a block of code a fixed number of times. Syntax:
for (initialization; condition; increment/decrement) {
// Code block
}