下面为正确的程序
#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);
}