在一个订单中我可以有多少个连续的嵌套指针(指针到指针)?做参考文献有限制吗?

发布于 2024-10-17 00:25:28 字数 393 浏览 4 评论 0原文

下面的程序声明了一个指针,然后又声明了一个新指针来保存前一个指针变量的地址。我可以使用多少嵌套指针变量来保存内存地址 有限制吗?

#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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

我还不会笑 2024-10-24 00:25:29

语言本身没有限制。指针变量的目的是存储地址。可以存储一个指向地址的指针,该指针指向一个地址,...,该指针指向一个地址。

但是,您使用这些类型的嵌套指针越多,您的代码就越难以理解。

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.

烈酒灼喉 2024-10-24 00:25:29

不,没有限制,因为它们都只是指向某个东西的指针,而它们指向的东西恰好是另一个指针。
你想尝试做一些实际的事情吗?
托德。

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.

满栀 2024-10-24 00:25:29

我能找到的唯一表明限制的语言如下:

5.2.4.1 翻译限制

1 实现应能够翻译并执行至少一个程序
至少包含以下每一项限制的一个实例:13)
...
— 12 个指针、数组和函数声明符(任意组合)修改一个
声明中的算术、结构、联合或不完整类型
...
— 逻辑源代码行中有 4095 个字符
...

The only language I could find that suggests a limit is the following:

5.2.4.1 Translation limits

1 The implementation shall be able to translate and execute at least one program that
contains at least one instance of every one of the following limits:13)
...
— 12 pointer, array, and function declarators (in any combinations) modifying an
arithmetic, structure, union, or incomplete type in a declaration
...
— 4095 characters in a logical source line
...

勿忘初心 2024-10-24 00:25:28

没有限制。指针是一块内存(通常是一个字),其内容是一个地址。指向指针的指针也是一个字,其内容是一个地址,但恰好该地址的内容是另一个地址。指向指针的指针(指向指向指针的指针……等等,令人作呕)并没有什么特别之处。

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).

情何以堪。 2024-10-24 00:25:28

没有限制。你甚至可以创建一个指向自身的指针,这是无限递归的:

void *p = &p;

There is no limit. You can even make a pointer that points at itself, which is infinitely recursive:

void *p = &p;
提笔落墨 2024-10-24 00:25:28

据我所知,除了系统内存限制(理论上)之外,不应该有任何限制。但这取决于所使用的编译器。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文