Basic C Notes
1. Introduction
- C is a general-purpose procedural programming language.
- Developed in the early 1970s by Dennis Ritchie.
2. Basic Syntax
- Every C program has a main() function.
- Statements end with a semicolon (;).
- Example:
#include <stdio.h>
int main() {
printf("Hello, World!\n");
return 0;
3. Variables and Data Types
- int, float, double, char, void
- Example:
int age = 30;
float pi = 3.14;
4. Input and Output
- Use scanf for input, printf for output.
- Example:
int number;
scanf("%d", &number);
printf("Number is %d\n", number);
5. Control Structures
- if, else if, else
- switch
- loops: for, while, do-while
6. Functions
- Declared with return type, name, and parameters.
- Example:
int add(int a, int b) {
return a + b;
7. Arrays
- Fixed size collection of elements.
- Example:
int arr[5] = {1, 2, 3, 4, 5};
8. Pointers
- Store memory addresses.
- Example:
int* ptr = &age;
9. Structures
- Group variables under one name.
- Example:
struct Point {
int x;
int y;
};
10. Comments
- Single line: //
- Multi-line: /* */