Back
Syntax
Study
Editor
Mode:
HTML
CSS
JavaScript
PHP
Reset
Run »
HTML / CSS / JS
#include <stdio.h> #include <stddef.h> /* NULL */ int main(void) { int value = 42; int *ptr = &value; /* ptr holds the address of value */ printf("value = %d ", value); printf("&value = %p ", (void *)&value); printf("ptr = %p ", (void *)ptr); /* same address */ printf("*ptr = %d ", *ptr); /* 42 */ /* Modifying through a pointer */ *ptr = 100; printf("value after *ptr=100: %d ", value); /* 100 */ /* Pointer to pointer */ int **pptr = &ptr; printf("**pptr = %d ", **pptr); /* 100 */ /* Null pointer check */ int *p = NULL; if (p == NULL) { printf("p is NULL — safe, not dereferencing "); } /* sizeof a pointer (platform-dependent) */ printf("sizeof(int *) = %zu bytes ", sizeof(int *)); /* Pointer comparison */ int arr[5] = {1, 2, 3, 4, 5}; int *start = arr; int *end = arr + 5; printf("Elements via comparison: "); for (int *q = start; q < end; q++) printf("%d ", *q); printf(" "); return 0; }
Result
Open