指针地址的含义是什么? [英] What is the meaning of the address of a pointer?
问题描述
如果我们有代码:
int b = 10;
int* a = &b;
std::cout << a << " " << &a << " ";
结果,地址不同.
但是指针的地址是什么意思?
But what's the meaning of address of a pointer?
由于我们的内存中有变量,所以指针具有变量地址的值.但是我们没有将address的值存储在内存中,那么为什么要有一个address的地址呢?
A pointer has the value of a variable's address, since we have a varaible in memory. But we don't have the value of address stored in memory, so why we have the address of an address?
也许我有一些误会,谢谢您的帮助.
Maybe I have some misunderstandings, thank you for your help.
推荐答案
请记住,您机器上的地址本身将是32位或64位值(取决于您的系统体系结构).
Remember an address on your machine is going to be, itself, a 32 or 64-bit value (depending on your system architecture).
在您的示例中,您有一个将值10存储在某个地址中的整数b,我们将其称为地址500
In your example, you have the integer b that stores the value 10 in some address, let's call it address 500
然后您有一个指针a,它存储着500的值,IT拥有自己的地址.
Then you have a pointer a, which stores the value 500, and IT has its own address.
有什么意义?实际上,您可以拥有双指针(或更多指针).
What's the point? You can actually have double-pointers (or more).
您了解
char* string = "hello";
string是一个指向字符数组开头的指针
string is a pointer to the beginning of an array of characters
然后
char** strings;
是指向char *的指针.例如,这就是您可以做一个数组数组的方式.
is a pointer to a char*. That's how you could do an array of arrays, for example.
这篇关于指针地址的含义是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!