zl程序教程

您现在的位置是:首页 >  后端

当前栏目

C语言函数结构体指针参数实现按索引取数组的返回值调用

C语言索引数组 实现 函数 参数 调用 结构
2023-09-14 09:09:14 时间

源码:

#include <stdio.h>
#include <string.h>
struct book
{
    int array[6];
    int num ;
};

int fun(struct book *q) //函数类型为double,返回值也必须是double
{
    int ret1;
    int ret2;
    int i;
    ret1 = q->num + 2020;
    ret2 = q->array[i] + 1; //C语言函数结构体指针参数实现按索引取数组的返回值调用

    return ret2; //返回指定类型的参数
    // return (ret1,ret2);//返回指定类型的参数
}

main()
{
    int array[6] = {0, 1, 2, 3, 4, 5};
    struct book boo = {array[2], 10};
    int num = fun(&boo);          //赋上参数
    printf("赋上参数======%d\n", num); //打印调用的计算结果
    return 0;
}

执行结果:

赋上参数======3
[Thread 47648.0x59d4 exited with code 0]
[Inferior 1 (process 47648) exited normally]