C LANGUAGE NOTES (FROM BASICS)
1. Introduction to C
- Developed by Dennis Ritchie (1972, AT&T; Bell Labs).
- General-purpose, procedural, middle-level language.
- Features: Fast execution, Portable, Structured, Rich operators.
2. Structure of a C Program
#include
int main() {
printf("Hello C");
return 0;
}
3. Basic Syntax
- Case-sensitive, ; ends statements, // comments, /* */ multi-line.
4. Data Types
int, char, float, double, array, pointer, structure, union, void.
5. Variables & Constants
int age = 20; const int PI = 3.14;
6. Operators
Arithmetic (+ - * / %), Relational (== != > <), Logical (&& || !),
Assignment (= +=), Increment (++ --), Bitwise (& | ^ << >>).
7. Input & Output
scanf("%d", #); printf("Value: %d", num);
8. Control Statements
if, else-if, else, switch-case.
9. Loops
for, while, do-while.
10. Arrays
int arr[5] = {1,2,3,4,5};
11. Strings
char name[20] = "C Language";
12. Functions
int add(int a, int b) { return a+b; }
13. Pointers
int *p = &x; printf("%d", *p);
14. Structures & Unions
struct student { int id; char name[20]; };
union data { int i; float f; };
15. File Handling
FILE *fp; fp=fopen("data.txt","w"); fprintf(fp,"Hello"); fclose(fp);
16. Keywords
auto, break, case, char, const, continue, default, do, double, else, enum,
extern, float, for, goto, if, int, long, register, return, short, signed,
sizeof, static, struct, switch, typedef, union, unsigned, void, volatile, while.