Complete C Programming Guide
1. Introduction to C Programming
C is a general-purpose programming language developed in the early 1970s by Dennis Ritchie at Bell Labs.
It is a powerful language that has influenced many modern programming languages.
Why learn C?
- It builds a strong foundation in programming concepts.
- C is used in system programming, embedded systems, operating systems, and more.
- It is extremely fast and efficient.
Basic Structure of a C Program:
```c
#include <stdio.h>
int main() {
printf("Hello, World!\n");
return 0;
```
Output:
Hello, World!
Complete C Programming Guide
2. Data Types and Variables
Data types define the type of data a variable can hold. Common data types in C include:
- int: for integers (e.g., 1, -5, 100)
- float: for floating-point numbers (e.g., 1.5, -3.2)
- double: for double-precision floating-point numbers
- char: for characters (e.g., 'a', 'Z')
- void: represents no value (used for functions)
Example:
```c
#include <stdio.h>
int main() {
int age = 18;
float weight = 65.5;
char grade = 'A';
printf("Age: %d\n", age);
printf("Weight: %.2f\n", weight);
printf("Grade: %c\n", grade);
return 0;
```
Output:
Age: 18
Weight: 65.50
Grade: A
Complete C Programming Guide
3. Control Structures
Control structures manage the flow of execution.
1. if-else statement:
```c
if (condition) {
// code if true
} else {
// code if false
```
2. switch statement:
```c
switch (value) {
case 1:
// code
break;
default:
// default code
```
3. Loops (while, for, do-while):
```c
for (int i = 0; i < 5; i++) {
printf("%d\n", i);
```
Complete C Programming Guide
Output: