Introduction to C
C is a powerful, general-purpose programming language developed by Dennis
Ritchie in 1972 at Bell Labs. Known for its efficiency and control, C is widely used
in systems programming, embedded systems, and application development.
Key Features:
Procedural Language
Low-level memory access
Portable and efficient
Basis for many modern languages like C++, Java, and Python
C Setup
To start coding in C, you need:
A text editor (e.g., VS Code, Sublime Text)
A C compiler (e.g., GCC, Clang)
Steps:
1. Install a C compiler.
2. Write a program in a .c file.
3. Compile using gcc filename.c.
4. Execute the generated binary file.
Syntax and Structure of C
C programs follow a specific structure:
#include <stdio.h> // Preprocessor directive
, int main() { // Entry point of the program
printf("Hello, World!\n");
return 0; // Exit status
}
Key Points:
Every program starts with main().
Use #include to include standard libraries.
Statements end with a semicolon ;.
Variables and Data Types in C
Variables store data, and data types define the type of data a variable can hold.
Basic Data Types:
int: Integer
float: Floating-point number
char: Character
double: Double-precision floating-point number
Example:
int age = 25;
float salary = 50000.50;
char grade = 'A';
Operators in C
Operators perform operations on variables and values.
Types of Operators:
1. Arithmetic: +, -, *, /, %