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. asp.net中用回车代替按钮事件

    第一步,先编写简单的页面代码,这里我们只需要一个按钮就足够了.当然,还有按钮事件. <html> <head> <title>测试绑定enter</title ...

  2. 解决ASP.NET网站发布问题

    目录 前言 开始 aspx.cs文件放到单独的类库项目 一个可选择勾选页面的发布工具:LimusicAddin 前言 Asp.net 发布分为:动态编译和预编译.预编译又分为:In Place Pre ...

  3. 【网络收集】Sql Server datetime 常用日期格式转换

    ) , sfrq, ) 我们经常出于某种目的需要使用各种各样的日期格式,当然我们可以使用字符串操作来构造各种日期格式,但是有现成的函数为什么不用呢? SQL Server中文版的默认的日期字段date ...

  4. 动态执行C#代码

    using System; using System.CodeDom.Compiler;using System.Collections.Generic;using System.Linq;using ...

  5. android 安装包签名问题探究

    1.首先先科普一下,android为什么需要给安装包签名: 所有的Android应用程序在发布之前都要求开发人员用一个证书进行数字签名,anroid系统不会安装没有进行签名的由于程序.    平时我们 ...

  6. jQuery实现CheckBox全选、全不选

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  7. CAF(C++ actor framework)使用随笔(同步发送 异步与同步等待)(三)

    c). 同步发送, 等待响应, 超时后收到1个系统消息. 贴上代码 #include <iostream> #include "caf/all.hpp" #includ ...

  8. lex&yacc8--wehter use in C++

    bintree.h:12:1: error: unknown type name ‘using’ using namespace std; ============== bintree.h:28:1: ...

  9. VS代码模板

    Microsoft Visual Studio 11.0\Common7\IDE\ItemTemplates\Csharp\Code\2052\Class

  10. L001-老男孩教育-Python13期VIP视频-19节-pbb

    L001-老男孩教育-Python13期VIP视频-19节-pbb Windows上安装 Python3开发环境 下载:www.python.org >选择Downloads>All re ...