1 结构体
#include <iostream>
#include <cstring>
using namespace std; void printBook( struct Book book ); struct Book
{
char title[];
char author[];
char subject[];
int book_id;
}; int main()
{
struct Book book1;
struct Book book2; strcpy( book1.title, "Learn c++ Programming");
strcpy( book1.author, "Chand Miyan");
strcpy( book1.subject, "c++ Programming");
book1.book_id = ; strcpy( book2.title, "Telecom Billing");
strcpy( book2.author, "Yakit Singha");
strcpy( book2.subject, "Telecom");
book2.book_id = ; cout << book1.title << " " << book1.author << " " << book1.subject << " " << book1.book_id << endl;
cout << book2.title << " " << book2.author << " " << book2.subject << " " << book2.book_id << endl; cout << "传入函数打印" << endl; printBook(book1);
printBook(book2); } void printBook( struct Book book )
{
cout << book.title << " " << book.author << " " << book.subject << " " << book.book_id << endl;
} /* vim: set ts=4 sw=4 sts=4 tw=100 */
2 指向结构的指针
#include <iostream>
#include <cstring> using namespace std; typedef struct
{
char title[];
char author[];
char subject[];
int book_id;
}Book; void printBook(Book *book); int main()
{
Book book1, book2; strcpy( book1.title, "Learn c++ Programming");
strcpy( book1.author, "Chand Miyan");
strcpy( book1.subject, "c++ Programming");
book1.book_id = ; strcpy( book2.title, "Telecom Billing");
strcpy( book2.author, "Yakit Singha");
strcpy( book2.subject, "Telecom");
book2.book_id = ; printBook(&book1);
printBook(&book2); long int a = ;
typedef long int *ptrLInt; ptrLInt x;
x = &a; cout << *x; } void printBook(Book *book)
{
//指向该结构的指针访问结构的成员,您必须使用 -> 运算符
cout << book->title << " " << book->author << " " << book->subject << " " << book->book_id << endl;
} /* vim: set ts=4 sw=4 sts=4 tw=100 */

结构体 typedef关键字的更多相关文章

  1. 我学C的那些年[ch02]:宏,结构体,typedef

    c语言的编译过程: 预处理 编译 汇编 链接 而预处理中有三种情况: 文件包含( #include ) 条件编译(#if,#ifndef,#endif) 宏定义( #define ) 宏就是预处理中的 ...

  2. 结构体 + typedef

    简单结构体 struct student{ char name[20];   //可以用scanf或者直接赋值 *如果用char *name  在用scanf时没有内存接收 long id; int ...

  3. c++结构体双关键字排序

    #include<bits/stdc++.h> using namespace std; struct node{ int l,r; }num[]; int w_comp(const no ...

  4. map中结构体做关键字的注意事项

    序: 今天做一道题,由于递归函数比较恶心,如果用记忆化搜索,数据范围极大却又用不全(二维数组存的话直接炸).所以决定干脆使用stl::map存储(反正有O2优化),但是执行insert的时候,编译器却 ...

  5. 结构体 typedef struct hash_cell_struct hash_cell_t;

    typedef struct hash_cell_struct hash_cell_t; struct hash_cell_struct{ void* node; /*!< hash chain ...

  6. 结构体typedef struct dtuple_struct dtuple_t;

    /** Structure for an SQL data tuple of fields (logical record) */ struct dtuple_struct { ulint info_ ...

  7. delphi 的结构体对齐关键字

    Align fields (Delphi)   Go Up to Delphi Compiler Directives (List) Index Type Switch Syntax {$A+}, { ...

  8. C语言——结构体

    struct 是一种把一些数据项组合在一起的数据结构.在Go,Rust这些新语言中都保留了结构体 struct 的概念,这是C的精华. 定义匿名结构体 例:学生信息定义为一个结构体,信息内容包括学生的 ...

  9. C语言如何定义结构体

    原文地址 1. struct与typedef struct区别 struct是结构体的关键字,用来声明结构体变量如 struct  student {   char  num[10];      ch ...

随机推荐

  1. Android 分析工具 APKAnalyser

    APKAnalyser 是 Android 静态,虚拟分析工具,用来测试和验证 Android 应用的开发工作.ApkAnalyser 是个完整的工具链,可以修改二进制应用.用户可以改装,安装,运行, ...

  2. Activity的启动模式(android:launchMode)

    在android里,有4种activity的启动模式,分别为: “standard” (默认) “singleTop” “singleTask” “singleInstance” 它们主要有如下不同: ...

  3. 【转】Android开发中Handler的使用

    在Android开发中,我们经常会遇到这样一种情况:在UI界面上进行某项操作后要执行一段很耗时的代码,比如我们在界面上点击了一个”下载“按钮,那么我们需要执行网络请求,这是一个耗时操作,因为不知道什么 ...

  4. sql常识-SQL 通配符

    在搜索数据库中的数据时,您可以使用 SQL 通配符. SQL 通配符 在搜索数据库中的数据时,SQL 通配符可以替代一个或多个字符. SQL 通配符必须与 LIKE 运算符一起使用. 在 SQL 中, ...

  5. 第六篇、微信小程序-form组件

    表单: 将组件内的用户输入的<switch/> <input/> <checkbox/> <slider/> <radio/> <pi ...

  6. 119. Pascal's Triangle II

    Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3,Return [1,3, ...

  7. CAF(C++ actor framework)使用随笔(unbecome与keep_behavior用法)

    看usermanual(使用随笔一里面有)看到差不多一半的时候,这个keep_behavior与unbeacome的结合引起了我的注意.(这是为什么呢?) 因为它的示例代码写的太简单了!我真的没看太懂 ...

  8. 使用DNSSCrypt解决DNS污染问题

    本文转自 月光博客,如有需要,请阅读原文. google近期在国内是不能访问了,dropbox这货居然也被DNS污染了,幸好发现DNSCrypt这一神器,防止DNS污染的绝佳工具. 基本原理:DNSC ...

  9. Linux 获取文件夹下的所有文件

    作者:jostree 转载请注明出处 http://www.cnblogs.com/jostree/p/4129616.html #include <string> #include &l ...

  10. 仿春雨医生 安卓app(android)

    仿春雨医生 安卓app(android) 目前APP处与开发完善中,可过程序自下载更新,如有BUG报错,请联系QQ 131 065 1206 支持安卓(android) .IOS(IPHONE),PA ...