C Programming Complete Beginner Guide (30
Pages)
Introduction to C
C is a powerful low-level programming language used for system programming, embedded
systems, and performance-critical applications.
#include <stdio.h>
int main(){
printf("Hello World");
return 0;
}
Variables & Data Types
Variables store data. Common types include int, float, char.
int a=10;
float b=5.5;
char c='A';
Input and Output
Use printf for output and scanf for input.
int x;
scanf("%d",&x);
printf("%d",x);
Operators
Operators perform operations like +, -, *, /.
int sum = 5 + 3;
If-Else Statements
Conditional execution.
if(x>0){ printf("Positive"); } else { printf("Negative"); }
Switch Case
Alternative to if-else.
switch(x){ case 1: printf("One"); break; }
Loops - For
Used for repeating tasks.
for(int i=0;i<5;i++){ printf("%d",i); }
Loops - While
Repeats while condition is true.
while(x>0){ x--; }
Loops - Do While
Executes at least once.
do{ x--; }while(x>0);
Functions
Functions reuse code.
int add(int a,int b){ return a+b; }
Arrays
Store multiple values.
int arr[5]={1,2,3,4,5};
Strings
Character arrays.
char str[]="Hello";
Pointers
Store memory addresses.
int a=10;
int *p=&a;
Pointer Arithmetic
Operations on pointers.
p++;
Dynamic Memory
Allocate memory using malloc.
int *p = malloc(sizeof(int));
Structures
Group variables.
struct student{ int id; };
Unions
Share memory.
union data{ int i; float f; };
File Handling
Read/write files.
FILE *f = fopen("[Link]","r");
Command Line Args
Arguments from terminal.
int main(int argc, char *argv[]){}
Recursion
Function calling itself.
int fact(int n){ if(n==0) return 1; return n*fact(n-1);}
Preprocessor
Macros and includes.
#define PI 3.14
Bitwise Operators
Operate on bits.
int x = 5 & 3;
Enums
Named constants.
enum day{MON,TUE};
Typedef
Rename types.
typedef int num;
Storage Classes
auto, static, extern.
static int x;
Error Handling
Basic checks.
if(ptr==NULL){ printf("Error"); }
Makefiles
Build automation.
gcc main.c -o app
Debugging
Using printf or gdb.
printf("Debug");
Mini Project
Simple calculator.
int main(){ int a,b; scanf("%d%d",&a,&b); printf("%d",a+b);}
Next Steps
Practice and build projects.