C Language Tutorial
(Basic to Advanced)
Topics to be covered :
Installation + Setup
Chapter 1 - Variables, Data types + Input/Output
Chapter 2 - Instructions & Operators
Chapter 3 - Conditional Statements
Chapter 4 - Loop Control Statements
Chapter 5 - Functions & Recursion
Chapter 6 - Pointers
Chapter 7 - Arrays
Chapter 8 - Strings
Chapter 9 - Structures
Chapter 10 - File I/O
Chapter 11 - Dynamic Memory Allocation
Dynamic Memory Allocation
(Chapter 11)
# include <stdio.h>
# include <stdlib.h>
//Dynamic Memory Allocation
int main() {
//sizeof function
printf("%d\n", sizeof(int));
printf("%d\n", sizeof(float));
printf("%d\n", sizeof(char));
//malloc
// int *ptr;
// ptr = (int *) malloc(5 * sizeof(int));
// for(int i=0; i<5; i++) {
// scanf("%d", &ptr[i]);
// }
// for(int i=0; i<5; i++) {
// printf("number %d = %d\n", i+1, ptr[i]);
// }
//calloc
int *ptr = (int *) calloc(5, sizeof(int));
for(int i=0; i<5; i++) {
printf("number %d = %d\n", i+1, ptr[i]);
}
//free
free(ptr);
return 0;
}