返回结构体指针c语言
发布时间: 2023-01-17 20:18:51
㈠ c语言函数能不能返回结构体
c语言函数可以返回结构体,操作方法如下:
1、首先在电脑中打开visual studio新建项目,给这个结构体取个名字叫student。
㈡ C语言返回结构的指针问题
直接把结构体变量传递参数是传值,
st *fun(struct st x)
这里的形参x其实是传递的实参y的拷贝,这和形参不能影响实参是同样的道理。而且x在fun函数结束后就被系统回收了,取得的地址当然就成野指针了,所以应该用结构体指针传递参数:
#include"stdio.h"
#include"string.h"
structst
{
inta;
charb[10];
};
voidfun(structst*px)
{
px->a=100;
strcpy(px->b,"99999");
}
intmain()
{
structsty,*p;
p=&y;
y.a=999;
strcpy(y.b,"0");
printf("y.a=%dy.b=%s ",y.a,y.b);
fun(p);
printf("(*p).a=%d(*p).b=%s ",(*p).a,(*p).b);
}
㈢ 求解一个c语言函数返回结构体指针的问题
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<fstream>
#include<stdlib.h>
usingnamespacestd;
typedefstructpoint{//结构体设计
intA,B,C,a,b,c,id,n;
}point;
point*ReadFile(){
staticpointss[110];
chardata[50]={'