


Also, since functions are just chunks of code in the computer’s memory, and each of them has its own address, you can create pointers to functions too, and knowing a function’s address in memory enables you to pass functions as parameters too, giving your functions the ability to switch among calling numerous functions. Knowing a variable’s address in memory enables you to pass the variable to a function by reference. Pointers are one of the more versatile features of C. (Pointers are so called because they point to a chunk of memory.) The address contained by a pointer is a lengthy number that enables you to pinpoint exactly where in the computer’s memory the variable resides. A pointer, then, is a special kind of variable that contains the location or address of that chunk of memory. In one sense, any variable in C is just a convenient label for a chunk of the computer’s memory that contains the variable’s data.

This can be observed with: readelf -l a.Pointers are the variables which are used to store/hold address of another variables. text in the same segment, which has execute but no write permission. Note however that the default linker script puts. So it gets stored in the stack (relative to %rbp). If we do the same for char: char s = "abc" If an attempt is made to use p to modify the contents of the array, the behavior is undefined.Ĭompile and decompile: gcc -ggdb -std=c99 -c main.cĨ: 48 c7 45 f8 00 00 00 movq $0x0,-0x8(%rbp)Ĭonclusion: GCC stores char* it in. On the other hand, the declaration char *p = "abc" ĭefines p with type "pointer to char" and initializes it to point to an object with type "array of char" with length 4 whose elements are initialized with a character string literal.

The contents of the arrays are modifiable. If you are just printing the two examples, it will perform exactly the same. The difference between char* the pointer and char the array is how you interact with them after you create them.
