一个if,else问题
假如有这样一个伪代码,最终要用C语言实现的:
typedef struct A
{
int data;
struct A * next;
}A,*B;
main()
{
int i-6;
B newnode;
B currentnode;
newnode=(B)malloc(sizeof(A));
newnode->data=i;
if(newnode->data<currentnode)
currentnode->next=newnode;
else
.......
}
这个伪代码中currentnode只定义了,没有赋值,在执行if,else时会出现什么样的情况,也就是怎么执行的
[解决办法]
if(newnode->data<currentnode)这句应该是这样吧:if(newnode->data<currentnode->data)即使修改后也是不确定吧。可能会出现错误,这种可能行很大。currentnode是野指针的。
[解决办法]
系统会调用当前地址上面的值 不管怎么说你的int分配的那个地址上面还是有数据的 就会是那个值 只不过这个值是随机的
[解决办法]