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

来源:互联网 发布:云服务器如何绑定域名 编辑:程序博客网 时间:2024/05/17 01:19

下面为正确的程序

#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);

}

 

 

 

 

原创粉丝点击