// 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};
*/
結構體的引用
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.