如何在C中使用while声明指向指针的多个指针?
我有以下代码:如何在C中使用while声明指向指针的多个指针?,c,loops,pointers,while-loop,C,Loops,Pointers,While Loop,我有以下代码: #include <unistd.h> #include <stdlib.h> #include <stdio.h> void ft_ultimate_ft(int *********nbr) { printf("%d", *********nbr); } int main(){ /*Start of problem*/ int *a; int **b = &a; int ***c = &am
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
void ft_ultimate_ft(int *********nbr)
{
printf("%d", *********nbr);
}
int main(){
/*Start of problem*/
int *a;
int **b = &a;
int ***c = &b;
int ****d = &c;
int *****e = &d;
int ******f = &e;
int *******g = &f;
int ********h = &g;
int *********i = &h;
/*end of problem*/
*********i = 42;
ft_ultimate_ft(i);
return 0;
}
#包括
#包括
#包括
无效英尺(国际**********nbr)
{
printf(“%d”,**********nbr);
}
int main(){
/*问题的开始*/
int*a;
int**b=&a;
int***c=&b;
int****d=&c;
int****e=&d;
int******f=&e;
int*******g=&f;
int*******h=&g;
int*********i=&h;
/*问题的结束*/
*********i=42;
ft_最终_ft(i);
返回0;
}
我需要在循环中包含指针到指针的声明(例如,while)。需要减少声明的数量。我假设我已经正确理解了您的问题,即使用循环创建指向数字的多个指针,然后为其赋值 我写了一段代码,部分完成了您的需求,但仍然需要知道循环后有多少层
#include <stdlib.h>
#include <stdio.h>
#include <malloc.h>
void ft_ultimate_ft(int *********nbr)
{
printf("%d", *********nbr);
}
int main() {
int t = 10;
int n = 8;
void * p = &t;
for (int i = 0; i < n; i++)
{
void* * s = (void **)malloc(sizeof(void*));
*s = p;
p = s;
}
/*end of problem*/
int *********real = (int *********)p;
*********real = 42;
ft_ultimate_ft(real);
return 0;
}
#包括
#包括
#包括
无效英尺(国际**********nbr)
{
printf(“%d”,**********nbr);
}
int main(){
int t=10;
int n=8;
无效*p=&t;
对于(int i=0;i
哪个输出42
未编写程序的清理部分
另外,在您的代码中,指针a是不确定的,我认为您的原始代码不能正常工作。这是什么?谁提出了这个要求?你为什么要这样做?无论如何,您可以循环值,而不是类型。您根本不担心
a
是不确定的,因此车轮完全从您已经乘坐的马车上掉下来了?请看:您不能在循环中执行此操作。星号的数量是类型的一部分,这个概念只在编译时存在。