Loading...
By KarnatakaPUCS Team on 7/10/2026
Pointers are one of the most powerful features of C programming. This guide helps you understand pointers and memory management concepts.
A pointer is a variable that stores the memory address of another variable:
c#include <stdio.h> int main() { int num = 42; int *ptr = # printf("Value: %d\n", num); printf("Address: %p\n", (void*)ptr); printf("Value via pointer: %d\n", *ptr); return 0; }
C provides functions for dynamic memory allocation:
c#include <stdlib.h> int main() { // Allocate memory for 5 integers int *arr = (int*)malloc(5 * sizeof(int)); if (arr == NULL) { fprintf(stderr, "Memory allocation failed\n"); return 1; } // Use the allocated memory for (int i = 0; i < 5; i++) { arr[i] = i * 10; } // Free the allocated memory free(arr); return 0; }