我有这个代码:
#include<stdio.h>
#include<stdlib.h>
struct node
{
int data;
struct node *next;
};
void pointerOfPointer(struct node **reference)
{
struct node *temporary = malloc(sizeof(struct node));
temporary->data = 100;
temporary->next = 0;
printf("before: temporary->data %d\n", temporary->data);
temporary = *reference;
printf("after: temporary->data %d\n", temporary->data);
}
int main()
{
struct node *linkedlist = malloc(sizeof(struct node));
linkedlist->data = 15;
linkedlist->next = 0;
pointerOfPointer(&linkedlist);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
如何在不将 *reference 地址复制到临时局部变量的情况下访问 pointerOfPointer 函数中指向结构指针的指针?所以最后我可以直接使用operator -> 访问引用变量数据,比如reference->data?
我有这个代码.为什么它会-nan在主程序中返回一个值时产生?
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cmath>
using namespace::std;
float f(float x)
{
float result = -5 * x * x - 2 * x + 1;
return powf(result, (float)1/(float)3);
}
int main()
{
cout<<f(-1)<<endl;
getchar();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
这让我很困惑.据我所知,我使用合适的数据类型.