C Programming - Basic Notes
1. Introduction to C
C is a general-purpose, procedural programming language.
Developed by Dennis Ritchie in 1972 at Bell Labs.
Used in system programming, embedded systems, and low-level memory management.
2. Structure of a C Program
#include <stdio.h>
int main() {
// Your code here
return 0;
- #include <stdio.h> : Preprocessor directive to include header
- main() : Entry point of a C program
- printf() : Used for output
- return 0; : Ends the program successfully
3. Data Types in C
- int : Integer numbers (e.g., int x = 10;)
- float : Decimal numbers (e.g., float y = 5.5;)
- char : Single character (e.g., char ch = 'A';)
- double : Larger decimal numbers (e.g., double d = 9.81;)
4. Variables and Constants
C Programming - Basic Notes
- Variable: A named space in memory to store data (e.g., int age = 20;)
- Constant: Fixed value that cannot be changed (e.g., const float PI = 3.14;)
5. Input and Output
Example:
#include <stdio.h>
int main() {
int age;
printf("Enter age: ");
scanf("%d", &age);
printf("Your age is %d", age);
return 0;
- printf(): Displays output
- scanf(): Takes input from user
6. Operators
- Arithmetic: +, -, *, /, %
- Relational: ==, !=, >, <, >=, <=
- Logical: &&, ||, !
- Assignment: =, +=, -=, etc.
7. Simple Example Code
C Programming - Basic Notes
#include <stdio.h>
int main() {
int a = 5, b = 3;
int sum = a + b;
printf("Sum is %d", sum);
return 0;