您的位置:首页 > 其它

函数用参数为 结构体指针 在VC下出现的问题

2007-11-16 18:02 295 查看
下面为正确的程序

#include"stdio.h"

struct par{
int x;
int y ;
} ;

struct par *par ;

int pprint(struct par *pstr ){

int z ;
z = (pstr->x) + (pstr->y) ;
return z ;
}

//*pstr = &pstra
//指针 地址

void main(){

int c ;

struct par pstra ;

pstra.x =1;
pstra.y =2;

c = pprint(&pstra);
printf("The c is %d",c);

}

下面为出现问题的程序

#include"stdio.h"

struct par{
int x;
int y ;
} ;

struct par *par ;

int pprint(struct par *pstr ){

int z ;
z = (pstr->x) + (pstr->y) ;
return z ;
}

//结果没打印 语法好像没错,结果?
void main(){

int c ;

struct par *pstra ;

pstra->x =1;
pstra->y =2;

c = pprint( pstra);
printf("The c is %d",c);

}

加 typedef struct 后

#include"stdio.h"

typedef struct par{
int x;
int y ;
} par1 ; // par1 <- struct par

int pprint(par *pstr ){

int z ;
z = (pstr->x) + (pstr->y) ;
return z ;
}

void main(){
int c ;

par *pstra ;

pstra->x =1;
pstra->y =2;

c = pprint( pstra);
printf("The c is %d",c);

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: