zoukankan      html  css  js  c++  java
  • (四)结构体

    #include <stdio.h>
    #include <string.h>
    
    typedef struct Books
    {
       char  title[50];
       char  author[50];
       char  subject[100];
       int   book_id;
    } Book;
    
    int main( )
    {
       Book book;
    
       strcpy( book.title, "C 教程");
       strcpy( book.author, "Runoob");
       strcpy( book.subject, "编程语言");
       book.book_id = 12345;
    
       printf( "书标题 : %s
    ", book.title);
       printf( "书作者 : %s
    ", book.author);
       printf( "书类目 : %s
    ", book.subject);
       printf( "书 ID : %d
    ", book.book_id);
    
       return 0;
    }
    #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 的地址来输出 Book1 信息 */
        printBook( &Book1 );
    
        /* 通过传 Book2 的地址来输出 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);
    }
  • 相关阅读:
    【hibernate】自定义转换器
    【hibernate】存储图片
    【hibernate】映射可嵌入式组件
    【hibernate】应用程序级别的视图
    adb shell模拟点击事件(input tap)
    Android UIAutomator 定位
    adb devices连接不上设备
    获取元素属性get_attribute
    wait_activity
    webview定位 & native和webview切换
  • 原文地址:https://www.cnblogs.com/huangjianping/p/8283636.html
Copyright © 2011-2022 走看看