在一个订单中我可以有多少个连续的嵌套指针(指针到指针)?做参考文献有限制吗?
下面的程序声明了一个指针,然后又声明了一个新指针来保存前一个指针变量的地址。我可以使用多少嵌套指针变量来保存内存地址 有限制吗?
#include <stdio.h>
#include <conio.h>
void main()
{
int x=2,y=5;
int *ptr;
int **sptr;
int ***ssptr;
ptr = &x; // address of x
*ptr = 0;
sptr = &ptr;
ssptr = & sptr;
printf(" address is ip = %u %u %u",ptr,sptr,ssptr);
_getch();
}
The follow program declares a pointer then again a new pointer to hold address of previous pointer variable.. How much can I use nested pointer variable to hold memory address
is there any limit?
#include <stdio.h>
#include <conio.h>
void main()
{
int x=2,y=5;
int *ptr;
int **sptr;
int ***ssptr;
ptr = &x; // address of x
*ptr = 0;
sptr = &ptr;
ssptr = & sptr;
printf(" address is ip = %u %u %u",ptr,sptr,ssptr);
_getch();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
语言本身没有限制。指针变量的目的是存储地址。可以存储一个指向地址的指针,该指针指向一个地址,...,该指针指向一个地址。
但是,您使用这些类型的嵌套指针越多,您的代码就越难以理解。
There is not a limit in the language itself. The purpose of a pointer variable is to store an address. It is possible to store a pointer which points to an address, which points to an address, ..., which points to an address.
However, the more you use these types of nested pointers, the less understandable your code will be.
不,没有限制,因为它们都只是指向某个东西的指针,而它们指向的东西恰好是另一个指针。
你想尝试做一些实际的事情吗?
托德。
No there is no limit because they are all just pointers to something, and the thing they point to just happens to be another pointer.
Are you trying to do something practical?
Todd.
我能找到的唯一表明限制的语言如下:
The only language I could find that suggests a limit is the following:
没有限制。指针是一块内存(通常是一个字),其内容是一个地址。指向指针的指针也是一个字,其内容是一个地址,但恰好该地址的内容是另一个地址。指向指针的指针(指向指向指针的指针……等等,令人作呕)并没有什么特别之处。
There is no limit. A pointer is a chunk of memory (typically one word) whose contents are an address. A pointer to a pointer is also a word whose contents are an address, but it just so happens that the contents at that address is another address. There is nothing particularly special about a pointer to a pointer (to a pointer to a pointer... etc., ad nauseum).
没有限制。你甚至可以创建一个指向自身的指针,这是无限递归的:
There is no limit. You can even make a pointer that points at itself, which is infinitely recursive:
据我所知,除了系统内存限制(理论上)之外,不应该有任何限制。但这取决于所使用的编译器。
As far as I know, there shouldn't be any limit except for system memory restrictions (in theory). This would depend on the compiler used though.