结构体 typedef关键字
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关键字的更多相关文章
- 我学C的那些年[ch02]:宏,结构体,typedef
c语言的编译过程: 预处理 编译 汇编 链接 而预处理中有三种情况: 文件包含( #include ) 条件编译(#if,#ifndef,#endif) 宏定义( #define ) 宏就是预处理中的 ...
- 结构体 + typedef
简单结构体 struct student{ char name[20]; //可以用scanf或者直接赋值 *如果用char *name 在用scanf时没有内存接收 long id; int ...
- c++结构体双关键字排序
#include<bits/stdc++.h> using namespace std; struct node{ int l,r; }num[]; int w_comp(const no ...
- map中结构体做关键字的注意事项
序: 今天做一道题,由于递归函数比较恶心,如果用记忆化搜索,数据范围极大却又用不全(二维数组存的话直接炸).所以决定干脆使用stl::map存储(反正有O2优化),但是执行insert的时候,编译器却 ...
- 结构体 typedef struct hash_cell_struct hash_cell_t;
typedef struct hash_cell_struct hash_cell_t; struct hash_cell_struct{ void* node; /*!< hash chain ...
- 结构体typedef struct dtuple_struct dtuple_t;
/** Structure for an SQL data tuple of fields (logical record) */ struct dtuple_struct { ulint info_ ...
- delphi 的结构体对齐关键字
Align fields (Delphi) Go Up to Delphi Compiler Directives (List) Index Type Switch Syntax {$A+}, { ...
- C语言——结构体
struct 是一种把一些数据项组合在一起的数据结构.在Go,Rust这些新语言中都保留了结构体 struct 的概念,这是C的精华. 定义匿名结构体 例:学生信息定义为一个结构体,信息内容包括学生的 ...
- C语言如何定义结构体
原文地址 1. struct与typedef struct区别 struct是结构体的关键字,用来声明结构体变量如 struct student { char num[10]; ch ...
随机推荐
- 什么是MVC开发模式以及它和传统开发模式的区别
Model1模式:使用纯JSP或者JSP+JavaBean开发,存在如下缺陷:JSP页面中混合了HTML和JAVA代码,从而给代码的开发和阅读带 来了麻烦:系统后期维护和扩展非常困难,例如在JSP页面 ...
- python - 图例显示中文
# -*- coding: utf-8 -*- """ Created on Mon Nov 30 13:24:00 2015 @author: jx_luo " ...
- C# @符号的多种使用方法
1.限定字符串用 @ 符号加在字符串前面表示其中的转义字符“不”被处理.如果我们写一个文件的路径,例如"D:/文本文件"路径下的text.txt文件,不加@符号的话写法如下:str ...
- How to Set Directory Permissions at Install Time using an MSI Created Using Windows Installer XML (WIX)
Original Link: http://blogs.msdn.com/b/cjacks/archive/2008/12/04/how-to-set-directory-permissions-a ...
- C++多线程技术windows常用方法
随着计算机CPU计算能力快速提高,计算机的处理性能和并行性能力也大大提升.那么,一味使用运行时标准库的C++语言也应该开始支持多线程技术.今天,我为大家带来了C++在windows平台下的常用多线程方 ...
- Poj OpenJudge 百练 2389 Bull Math
1.Link: http://poj.org/problem?id=2389 http://bailian.openjudge.cn/practice/2389/ 2.Content: Bull Ma ...
- windows同时安装两个jdk
两个项目需求不同,需要不同的jdk(1.7,1.8),所以每次切换项目的时候就会重新卸载原有的,在安装新的,比较麻烦. 就查资料看可以同时安装多个jdk,但是每次只能配置一个环境变量.安装的时候还是遇 ...
- d3 之deal with data
之前说慢慢写有关D3的笔记,结果做完那个拓扑图就没写了,今天发现关于d3的用法有点遗忘.感觉有回顾一遍的必要. 之前的序对D3有一个简单的介绍,下面就做一些细节的东西.主要是贴代码,顺带注释和效果图. ...
- linux 常用软件安装-目录
nginx apache php mysql oracle tomcat memcached mongodb sqlserver
- centos7搭建NIS与NFS综合应用
实验环境: centos7(服务端) redhat enterprise linux 7.2(客户端) 实验目的:用centos7的账号,能在redhat enterprise linu ...