zoukankan      html  css  js  c++  java
  • C语言

    访问结构成员

    #include <stdio.h>
    #include <string.h>
    
    struct Books
    {
       char  title[50];
       char  author[50];
       char  subject[100];
       int   book_id;
    };
    
    int main( )
    {
       struct Books Book1;        /* 声明 Book1,类型为 Books */
       struct Books Book2;        /* 声明 Book2,类型为 Books */
    
       /* Book1 详述 */
       strcpy( Book1.title, "C Programming");
       strcpy( Book1.author, "Nuha Ali");
       strcpy( Book1.subject, "C Programming Tutorial");
       Book1.book_id = 6495407;
    
       /* Book2 详述 */
       strcpy( Book2.title, "Telecom Billing");
       strcpy( Book2.author, "Zara Ali");
       strcpy( Book2.subject, "Telecom Billing Tutorial");
       Book2.book_id = 6495700;
    
       /* 输出 Book1 信息 */
       printf( "Book 1 title : %s
    ", Book1.title);
       printf( "Book 1 author : %s
    ", Book1.author);
       printf( "Book 1 subject : %s
    ", Book1.subject);
       printf( "Book 1 book_id : %d
    ", Book1.book_id);
    
       /* 输出 Book2 信息 */
       printf( "Book 2 title : %s
    ", Book2.title);
       printf( "Book 2 author : %s
    ", Book2.author);
       printf( "Book 2 subject : %s
    ", Book2.subject);
       printf( "Book 2 book_id : %d
    ", Book2.book_id);
    
       return 0;
    }
    
    
    Book 1 title : C Programming
    Book 1 author : Nuha Ali
    Book 1 subject : C Programming Tutorial
    Book 1 book_id : 6495407
    Book 2 title : Telecom Billing
    Book 2 author : Zara Ali
    Book 2 subject : Telecom Billing Tutorial
    Book 2 book_id : 6495700
    

    结构作为函数参数

    #include <stdio.h>
    #include <string.h>
    
    struct Books
    {
       char  title[50];
       char  author[50];
       char  subject[100];
       int   book_id;
    };
    
    /* 函数声明 */
    void printBook( struct Books book );
    int main( )
    {
       struct Books Book1;        /* 声明 Book1,类型为 Books */
       struct Books Book2;        /* 声明 Book2,类型为 Books */
    
       /* Book1 详述 */
       strcpy( Book1.title, "C Programming");
       strcpy( Book1.author, "Nuha Ali");
       strcpy( Book1.subject, "C Programming Tutorial");
       Book1.book_id = 6495407;
    
       /* Book2 详述 */
       strcpy( Book2.title, "Telecom Billing");
       strcpy( Book2.author, "Zara Ali");
       strcpy( Book2.subject, "Telecom Billing Tutorial");
       Book2.book_id = 6495700;
    
       /* 输出 Book1 信息 */
       printBook( Book1 );
    
       /* 输出 Book2 信息 */
       printBook( Book2 );
    
       return 0;
    }
    void printBook( struct Books book )
    {
       printf( "Book title : %s
    ", book.title);
       printf( "Book author : %s
    ", book.author);
       printf( "Book subject : %s
    ", book.subject);
       printf( "Book book_id : %d
    ", book.book_id);
    }
    
    
    Book title : C Programming
    Book author : Nuha Ali
    Book subject : C Programming Tutorial
    Book book_id : 6495407
    Book title : Telecom Billing
    Book author : Zara Ali
    Book subject : Telecom Billing Tutorial
    Book book_id : 6495700
    
  • 相关阅读:
    网页中的图片查看器viewjs使用
    检测和删除多余无用的css
    网页中插入视频的方案
    WebSocket使用教程
    JS+CSS简单实现DIV遮罩层显示隐藏【转藏】
    使用GPS经纬度定位附近地点(某一点范围内查询)
    使用SQL Server Management Studio 创建数据库备份作业
    SVN trunk(主线) branch(分支) tag(标记) 用法详解和详细操作步骤
    关于LINQ方方面面的入门、进阶、深入的文章。
    LINQ体验(7)——LINQ to SQL语句之Group By/Having和Exists/In/Any/All/Contains
  • 原文地址:https://www.cnblogs.com/jiqing9006/p/8278393.html
Copyright © 2011-2022 走看看