logo

The address of an array in C (in-depth)

#include <stdio.h> #include <stdlib.h> #include <string.h> void printArray(char** arr, size_t num) { int i; for (i = 0; i < num; i++) { printf("%s\n", arr[i]); // arr[0] <=> *arr } } int main(int argc, char* argv[]) { char* elem = "Example string"; char* ref = &elem[0]; // -- begin stack // ... // 8 bytes - char* -> 'E' // ... // -- end stack // &ref -> ref -> elem[0] printf("&ref: %p\n", &ref); printf("ref: %p\n", ref); printfArray(&ref, 1); return 0; }
Course thumb

The C programming language made simple

Courses with this lesson