zl程序教程

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

当前栏目

C语言函数结构体指针参数的指针赋值应用与主函数的赋值

C语言应用 函数 参数 结构 指针 赋值
2023-09-14 09:09:14 时间
#include <stdio.h>
#include <string.h>
#define format "%d\n%s\n%f\n%f\n%f\n"
struct book
{
    char bookname[30];
    double quantity;
};

void fun(struct book *p)
{
    /*这里的结果反调用main函数中给出的赋值*/
    printf("The book \" %s\" has \n", p->bookname);
    p->quantity -= 3.5;//减去3。5,函数中计算后主函数中调用自然减去3
    p->bookname;
}

void fun2(struct book *q)
{
    return q->quantity;
}

main()
{
    void fun(struct book *p);
    struct book book1 = {"Programming in C", 10};
    fun(&book1);
    printf("%lf《----------- copies\n", book1.quantity);
    printf("%s《----------- name\n", book1.bookname);

    void fun2(struct book *q);
    struct book book2 = {"wo----",10};
    fun2(&book2);
    printf("%s《--------- value\n", book2.bookname);
}

执行结果:10-3.5=6.5

The book " Programming in C" has
6.500000----------- copies
Programming in C《----------- name
wo------------- value
[Thread 2656.0xbaf0 exited with code 25]
[Inferior 1 (process 2656) exited with code 031]