C Programming Complete Tutorial Extended
C Programming Complete Tutorial Extended
Introduction to C Programming
Bell Labs. It has influenced many other languages and is widely used for system and application
development.
Example:
#include <stdio.h>
int main() {
printf("Hello, World!");
return 0;
Output:
Hello, World!
Example:
#include <stdio.h>
int main() {
return 0;
Output:
Age: 25
Salary: 55000.50
Grade: A
Conditional Statements
Example:
#include <stdio.h>
int main() {
if (num > 0) {
printf("Positive number");
} else {
printf("Non-positive number");
return 0;
Output:
Positive number
Loops in C
#include <stdio.h>
int main() {
printf("%d\n", i);
return 0;
Output:
4
5
Functions in C
Example:
#include <stdio.h>
void greet() {
printf("Welcome to C Programming!");
int main() {
greet();
return 0;
Output:
Welcome to C Programming!
Arrays in C
Example:
#include <stdio.h>
int main() {
int arr[5] = {1, 2, 3, 4, 5};
printf("%d\n", arr[i]);
return 0;
Output:
Pointers in C
Pointers are variables that store the memory address of another variable.
Example:
#include <stdio.h>
int main() {
int x = 10;
int *p = &x;
return 0;
Output:
Value of x: 10
Value pointed by p: 10
Structures in C
Structures are used to group different types of variables under one name.
Example:
#include <stdio.h>
struct Student {
int id;
char name[50];
float marks;
};
int main() {
struct Student s1 = {1, "John", 85.5};
return 0;
Output:
ID: 1
Name: John
Marks: 85.50
File Handling in C
#include <stdio.h>
int main() {
if (fptr == NULL) {
return 1;
}
fprintf(fptr, "Hello File!");
fclose(fptr);
return 0;
#include <stdio.h>
int main() {
char ch;
if (fptr == NULL) {
return 1;
putchar(ch);
fclose(fptr);
return 0;
Output:
Hello File!
Dynamic Memory Allocation
C provides malloc(), calloc(), realloc(), and free() for dynamic memory management.
Example:
#include <stdio.h>
#include <stdlib.h>
int main() {
int *ptr;
int n = 5;
if (ptr == NULL) {
return 1;
ptr[i] = i + 1;
}
free(ptr);
return 0;
Output:
12345