qfedu-cpp-level/day2/d6.cpp

30 lines
439 B
C++

// 指针的引用
// 为指针取个别名,相当于'指针的指针'
#include <iostream>
#include <cstdlib>
using namespace std;
struct STU
{
int sid;
float score;
};
void set_score(STU *&q, int sid, float score)
{
q->sid = sid;
q->score = score;
}
int main()
{
STU *p = (STU *)malloc(sizeof(STU));
set_score(p, 1, 99);
cout << "sid = " << p->sid << ", score = " << p->score << endl;
return 0;
}