// structurereference.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "iostream"
using namespace std;
typedef struct str
{
int val;
int x;
int y;
}pos;
void F(pos &ref)// &或*匀可实现val++,但直接p作实参时不能实现val++。
{
ref.val ++;
}
int _tmain(int argc, _TCHAR* argv[])
{
pos p;
p.x = 0;
p.y = 0;
cin>>p.val;
F(p);
cout<<p.val;
char c;
cin>>c;
return 0;
}
/* 结构体赋值:
允许 pos p = {1, 2, 3};
但不允许 pos p; p = {1, 2, 3};
*/
结构体的引用
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.