#include <stdio.h>
#include <stdlib.h> struct student{
int num;
char str[];
double dec;
}; void scan(struct student *stu[], int *n){
scanf("%d", n);
*stu = (struct student *)malloc(*n * sizeof(struct student)); for(int i = ; i < *n; ++i){
scanf("%d%s%lf", &(*stu)[i].num, (*stu)[i].str, &(*stu)[i].dec);
}
} void print(struct student stu[], int n){ printf("%d\n", n);
for(int i = ; i < n; ++i){
printf("%d %s %lf\n", stu[i].num, stu[i].str, stu[i].dec);
}
} int main(){
int n;
struct student *stu; scan(&stu, &n);
print(stu, n); free(stu);
return ;
}
/*
3
20 字符串0 20.02
21 字符串1 21.12
22 字符串2 22.22
*/

C/C++ 结构体 指针 函数传递的更多相关文章

  1. C语言结构体及函数传递数组參数演示样例

    注:makeSphere()函数返回Sphere结构体,main函数中.调用makeSphere()函数,传递的第一个參数为数组,传递的数组作为指针.

  2. C/C++ 结构体 数组 函数传递

    #include <stdio.h> #include <stdlib.h> struct student{ int num; ]; double dec; }; void s ...

  3. C与指针(结构体指针,函数指针,数组指针,指针数组)定义与使用

    类型 普通指针 指针数组(非指针类型) 数组指针 结构体指针 函数指针 二重指针 定义方式 int *p; int *p[5]; int (*p)[5]; int a[3][5]; struct{.. ...

  4. [编程] C语言结构体指针作为函数参数

    结构体指针作为函数参数:结构体变量名代表的是整个集合本身,作为函数参数时传递的整个集合,也就是所有成员,而不是像数组一样被编译器转换成一个指针.如果结构体成员较多,尤其是成员为数组时,传送的时间和空间 ...

  5. go语言结构体作为函数参数,采用的是值传递

    经过验证,go语言结构体作为函数参数,采用的是值传递.所以对于大型结构体传参,考虑到值传递的性能损耗,最好能采用指针传递. 验证代码: package main import ( "fmt& ...

  6. C语言--- 高级指针2(结构体指针,数组作为函数参数)

    一.结构体指针 1. 什么是结构体指针?指向结构体变量的指针     结构体:     typedef  struct stu{                          char name[ ...

  7. 【C++】结构体/结构体数组/结构体指针/结构体嵌套/函数参数/const

    一.结构体声明 struct Student { //成员列表 string name; int age; int score; }; //s3;定义时直接声明 int main() { struct ...

  8. python 传递结构体指针到 c++ dll

    CMakeLists.txt # project(工程名) project(xxx) # add_library(链接库名称 SHARED 链接库代码) add_library(xxx SHARED ...

  9. go语言基础之结构体做函数参数 值传递和地址传递

    1.结构体做函数参数值传递 示例: package main //必须有个main包 import "fmt" //定义一个结构体类型 type Student struct { ...

随机推荐

  1. psql-10权限和事务

    用户和角色 用户和角色在整个数据库实例中都是全局的;

  2. XML序列化及反序列化

    //对象序列化xml OutModel outmodel = new OutModel(); XmlSerializer serializer = new XmlSerializer(typeof(O ...

  3. MySQL 存储过程基本函数

    字符串类 CHARSET(str) //返回字串字符集CONCAT (string2 [,... ]) //连接字串INSTR (string ,substring ) //返回substring首次 ...

  4. Java 常用方法

    java 图片上传from表单必加属性:enctype="multipart/form-data" 1.获取字符串的长度 : length() 2 .判断字符串的前缀或后缀与已知字 ...

  5. Nagios配置文件详解

    首先要看看目前Nagios的主配置路径下有哪些文件.[root@nagios etc]# ll总用量 152-rwxrwxr-x. 1 nagios nagios 1825 9月  24 14:40 ...

  6. css样式

    这是CSS的定义经常用到的样式: body{ width:100%; background:#000; text-align:center;font:12px "宋体", Aria ...

  7. js的三种继承方式及其优缺点

    [转] 第一种,prototype的方式: //父类 function person(){ this.hair = 'black'; this.eye = 'black'; this.skin = ' ...

  8. HTML语法大全

      卷标 , 属性名称 , 简介  002 <! - - ... - -> 批注  003 <!> 跑马灯  004 <marquee>...</marque ...

  9. Java备份Oracle数据库

    Java备份Oracle数据库 Java线程.Process.ProcessBuilder 2010 年 6 月 20 日 文章内容描述了使用Java执行外部Oracle导出命令备份数据库功能的示例, ...

  10. jenkins使用git SCM时changelog乱码(Jenkins部署在Linux上,任务在Windows Slave上构建)

    问题原因 changelog的获取方式(git-client插件): 首先调用git whatchanged命令,读取输出字节流(UTF-8编码的Commit Message). 将字节流解码为字符串 ...