带指针的错误C ++结构 [英] Error C++ struct with pointer
本文介绍了带指针的错误C ++结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
帮助pliss ,,
i有问题,
我负责用指针制作项目结构;
like这个,
结构无论{
int next;
int previous;
int value = 5;
};
所以如果用户输入:
1 1
显示5,
如果用户输入:
2 1 3,
2 3 7,
value = 3,5,7
如果用户输入:
3 2;
value = 3,7;
5是擦除..
但是这个程序只是使用指针和结构,帮助请
我尝试了什么:
i尝试创建这个程序2天但没有结果:(
help pliss,,
i have a problem,,
I'm in charge of making a project struct with pointer;
like this,,
struct whatever{
int next;
int previous;
int value = 5;
};
so if the user input:
1 1
display 5,
if user input :
2 1 3,
2 3 7,
value = 3,5,7
if user input :
3 2;
value = 3,7;
5 is erase..
but this program just use pointer and struct, help pls
What I have tried:
i try to creat this program 2 day but no result:(
推荐答案
这个link[ ^ ]会帮助你。
那些不是指针。
对于可用作节点的结构,请尝试以下方法:
Those aren't pointers.
For a struct that you can use as a node, try this:
#include <stdio.h>
#include <stdlib.h>
struct whatever{
struct whatever *next;
struct whatever *previous;
int value;
};
int main()
{
struct whatever * node1 = (struct whatever*)malloc(sizeof(struct whatever));
node1->value = 100;
struct whatever * node2 = (struct whatever*)malloc(sizeof(struct whatever));
node2->value = 200;
node1->next = node2;
node2->previous = node1;
...
//release the memory
free(node1);
free(node2);
return 0;
}
这篇关于带指针的错误C ++结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文