当前位置:三九宝宝网 → 宝宝教育 → 教学论文 → 正文

关于c语言中的结构体数组作为函数参数传递的

更新:02-07 整理:39baobao.com
字体:

[C语言中对字符串进行操作的标准库函数有哪些]1)字符串操作 strcpy(p, p1) 复制字符串 strncpy(p, p1, n) 复制指定长度字符串 strcat(p, p1) 附加字符串 strncat(p, p1, n) 附加指定长度字符串 strlen(p) 取字符串长度 s...+阅读

1、结构体数组传给指针,实质上是不可能的,本质上传的是数组首地址,根据偏移来操作数组,这样看起来好像是真在操作数组一样。就和普通指针一样使用,只不过它是结构体数组。

2、例程:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

typedefstructStudent

{

charname[10] ;

intage ;

}Student;

#define LEN 10

//print all Student infomation

voidfun(Student *pStu,intlen)

{

inti ;

for(i = 0 ;i < len ;++i)

{

printf("%s\t%d",pStu[i].name,pStu[i].age) ;

}

}

intmain ()

{

Student stu[LEN] ;

fun(stu,LEN) ;

}

本文地址:https://www.39baobao.com/show/29_37340.html

以上内容来自互联网,请自行判断内容的正确性。若本站收录的信息无意侵犯了贵司版权,请联系我们,我们会及时处理和回复,谢谢.

以下为关联文档:

C语言结构体数组的定义1、C语言结构体数组的定义:数组是有序的并且具有相同类型的数据的集合。 2、结构数组就是具有相同结构类型的变量集合。假如要用C语言,定义一个班级40个同学的姓名、性别、年...

C语言程序设计数组指针与字符串程序我在vc6.0上调试过了,能通过。 希望对你有所参考。 #include<iostream> using namespace std; int* min(int*array,int*s) { for(int i=0;i<5;i++) { for(int j=5*i;j<5*...

C语言字符指针数组#include"stdio.h" #include #define A 7 void main() { int i; char **p; p=(char **)malloc(sizeof(char *)); for(i=0;i p[i]=(char*)malloc(sizeof(char)); for(i=0;i { g...

C语言通用函数字符指针数组寻找指定字符串#includenbsp;“stdafx.h“#includenbsp;amp;lt;stdio.hamp;gt;#includenbsp;amp;lt;string.hamp;gt;intnbsp;str2str(constnbsp;charnbsp;*str,nbsp;constnbsp;charnbsp;*s...

字符串数组与字符指针的区别一、 读写能力 char *a = “abcd”; 此时"abcd"存放在常量区。通过指针只可以访问字符串常量,而不可以改变它。 而char a[20] = “abcd”; 此时 "abcd"存放在栈。可以通过指针去访...

c语言字符数组指针#include "stdio.h" #include "string.h" void main() { char a[81]=""; char *p=a; int n,k,pos; puts("input the data"); gets(a); n=strlen(a); puts("the position you want to...

关于c中的指针字符串数组嘎刚学c求高手指教啊这问题简单:例 strcpy(p[0],"数学") printf("%s\n",p[0]); 输出数学,这个你应该明白。char *p[3]; p[0]="数学";这里的的先定义一个指针数组,强调是一个数组,3个元素,每个元素都是一个指针...

c语言创建单向链表函数void inputinfo(stu_info **head,int n) { int i=1; stu_info *loc_head=NULL,*tail; loc_head=(stu_info *)malloc(sizeof(stu_info)); tail=loc_head; for(i=1;i<=n;i++)...

Python向怎么向C语言传递结构体况如下: 打算从Python发一个TCP数据包给远程服务器,数据的主体是一个C语言的 struct (较大,size 为1402)。由于这个struct太复杂,故不打算在python 处对其重新定义,目前的想法是用p...