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. JS轮播图

    <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...

  2. 第九章 jQuery验证插件简介

    1. 表单验证插件-----Validation <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ...

  3. python - 图例显示中文

    # -*- coding: utf-8 -*- """ Created on Mon Nov 30 13:24:00 2015 @author: jx_luo " ...

  4. .net转java了

    公司技术部门  要求.net全体转向java 本来要看看.net core的 看来是没必要了  现在国内互联网公司.net是越来越少  不知道为何会这样 不过java的生态圈 确实是很强大 也很丰富 ...

  5. c#输出json,其中包含子json (可以含 无限级 子json)的方法思路

    首页 给出  DataTable 转Json 的方法: public static string TableToJson(DataTable dt) { List<Dictionary<s ...

  6. 在ASP.NET中实现压缩多个文件为.zip文件,实现批量下载功能 (转载并优化处理篇)

    转自:http://blog.csdn.net/yanlele424/article/details/6895986 这段时间一直在做一个网站,其中遇到了一个问题,就是在服务器端压缩多个服务器端的文件 ...

  7. flex_播放视频_本地_与_FMS端

    <?xml version="1.0" encoding="utf-8"?> <s:Application xmlns:fx="ht ...

  8. Linux SCSI回调IO的分析

    本文转载自:http://blog.csdn.net/xushiyan/article/details/6941640,如需参考,请访问原始链接地址. 没找到如何转载的入口,只好全文copy了. -- ...

  9. 【转载】分享下多年积累的对JAVA程序员成长之路的总结

    注:该文是从百度贴吧转载过来,之前看到觉得写得还不错,对Java开发学习者来说很有意义的,可以看看. 我也搞了几年JAVA了,由于一向懒惰,没有成为大牛,只是一普通程序猿,不爱玩社交网站,不爱玩微博, ...

  10. 一个功能齐全的IOS音乐播放器应用源码

    该源码是在ios教程网拿过来的,一个不错的IOS音乐播放器应用源码,这个是我当时进公司时 我用了一晚上写的  图片都是在别的地方扒的,主要是歌词同步,及上一曲,下一曲,功能齐全了 ,大家可以学习一下吧 ...