结构体 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 ...
随机推荐
- Jersey(1.19.1) - JSON Support
Jersey JSON support comes as a set of JAX-RS MessageBodyReader<T> and MessageBodyWriter<T&g ...
- Linux 命令 - rm: 删除文件和目录
命令格式 rm [OPTION]... FILE... 命令参数 -f, --force 强制删除,忽略不存在的文件,不会提示. -i, --interactive 没次删除文件时,提示用户确认. - ...
- 【AngularJs】---实现select的ng-options
controller .controller('MainController', function($scope, $http, $ionicModal, $timeout) { var post = ...
- android手机操作SD的使用方法
写入SD卡 package com.example.openfileproject; import java.io.File; import java.io.FileInputStream; impo ...
- Ajax概述
- 【oracle】oracle函数-数值函数
一.数值函数 1. mod(m,n) 求余函数 注意:若m或者n为null,则返回null.若n为0,则返回m的值 eg:
- 第二篇、为UITableViewCell 高度自适应加速 缓存cell的高度
通过NSCache缓存已经算好的行高 @interface ZHCellHeightCalculator : NSObject //系统计算高度后缓存进cache -(void)setHeight:( ...
- TTTAttributedLabel 如何将多个字符串高亮显示
TTTAttributedLabel进行多个字符串的高亮显示. 需要对每个字符串进行匹配,从而得到所有需要高亮的NSRange,然后利用NSMutableAttributedString对每个NSRa ...
- dorado7 重装了tomcat后配置路径
在Windows->Preferences->Server->Runtime Environments把先前的工程Servers删除掉
- 点线图中的A*算法
A*简介 A*(A-Star)算法是一种启发式算法,是静态路网中求解最短路最有效的方法.公式表示为:f(n)=g(n)+h(n), 其中f(n) 是节点n从初始点到目标点的估价函数, g(n) 是在状 ...