How can I put the address of the array into a variable?
char * str1 = "Hello";
int add = 0;
Now I want to put the address of the array into add.
I know I can print out the address of the array by the following way:
printf("Address = %p", str1);
But, I want to store the address in the variable.
If you want to store a memory address in a variable, the correct way is to type the variable as
std::intptr_torstd::uintptr_t. That is because these types are guaranteed large enough to hold any memory address:Apart from that, note that the value of
str1is already a memory address (it points toH) albeit a different one from the value of&str1(which points tostr1).