Program Console Vignaankosh.com
Execution Panel
Console is empty.
Null pointer handling is an interactive C dry run visualizer from the Pointersintro programs section. Study the source code, then use the execution controls to follow each step, variable update, highlighted line, and console output.
This page provides a browser-based dry run with source-code highlighting, auto-scroll, voice narration controls, and execution output for learning the program step by step.
#include <stdio.h>
#include <stdlib.h>
void safePrint(int *ptr) {
if(ptr == NULL) {
printf("Pointer is NULL, cannot dereference!\n");
return;
}
printf("Value: %d\n", *ptr);
}
int main() {
int *ptr1 = NULL; // Null pointer
int *ptr2 = malloc(sizeof(int)); // Allocate memory
if(ptr2 != NULL) {
*ptr2 = 42;
}
printf("ptr1: ");
safePrint(ptr1);
printf("ptr2: ");
safePrint(ptr2);
// Common null pointer checks
if(ptr1 == NULL) {
printf("\nptr1 is NULL - safe to check\n");
}
// Never dereference NULL pointer
// int x = *ptr1; // CRASH! Segmentation fault
free(ptr2);
ptr2 = NULL; // Good practice after free
return 0;
}