#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. IDE-Sublime【2】-代码智能提示插件SublimeCodeIntel的安装

    一.打开菜单References -> Package Control 二.输入Package Control: install Package,回车 三.输入SublimeCodeIntel, ...

  2. Spring任务调度之Quartz

    一.Quartz作业类的继承方式来讲,可以分为两类: 作业类需要继承自特定的作业类基类,如Quartz中需要继承自org.springframework.scheduling.quartz.Quart ...

  3. Jmeter性能测试 入门

    Jmeter是一款优秀的开源测试工具, 是每个资深测试工程师,必须掌握的测试工具,熟练使用Jmeter能大大提高工作效率. 熟练使用Jmeter后, 能用Jmeter搞定的事情,你就不会使用LoadR ...

  4. python 之 前端初识 html

    html语法代码示例 <!DOCTYPE html> <html lang="en"> <head> <meta charset=&quo ...

  5. Node.js exports与module.exports的关系

    今天搜索module.exports时看到CNode社区上发的Hack Sparrow一篇相关文章的链接 Node.js Module – exports vs module.exports 一篇5年 ...

  6. 【hihoCoder】1039 : 字符消除

    题目:http://hihocoder.com/problemset/problem/1039 给定一个字符串s,只包含'A', 'B', 'C'三种字符 1. 向 s 的任意位置 (包括头和尾) 中 ...

  7. *HDU2473 并查集

    Junk-Mail Filter Time Limit: 15000/8000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  8. iTop Webservice列表

    { u'operations':[ { u'verb':u'core/create', u'description':u'Create an object', u'extension':u'CoreS ...

  9. 将f2fs文件系统到磁盘

    1·   用git下载f2fs文件系统tools的源代码.下载地址如下:http://git.kernel.org/cgit/linux/kernel/git/jaegeuk/f2fs-tools.g ...

  10. Win7 下安装VirtualBox 没有Ubuntu 64bit 选项问题

    参考: win7安装virtualbox遇到的问题 基于VirtualBox虚拟机安装Ubuntu图文教程 问题 在安装VirtualBox之后,选择虚拟机进行安装的时候发现没有Ubuntu 64bi ...