c ++查找字符串_C ++结构| 查找输出程序| 套装2
c ++查找字符串
Program 1:
程序1:
#include <iostream>
using namespace std;
int main()
{
typedef struct
{
int A;
char* STR;
} S;
S ob = { 10, "india" };
S* ptr;
ptr = &ob;
cout << ptr->A << " " << ptr->STR[2];
return 0;
}
Output:
输出:
10 d
Explanation:
说明:
Here, we created a local structure with two members A and STR that is defined in the main() function. and created the object that is ob, and a pointer ptr, assigned the address of ob to ptr.
在这里,我们用main()函数中定义的两个成员A和STR创建了一个本地结构。 并创建对象ob和一个指针ptr,将ob的地址分配给ptr 。
cout <<ptr->A<<" "<<ptr->STR[2];
Here, we accessed elements using referential operator "->".
在这里,我们使用引用运算符“ -> ”访问元素。
ptr->A will be "10" and ptr->STR[2] will "d", it will access the 2nd element of the string STR.
ptr-> A将为“ 10”,而ptr-> STR [2]将为“ d” ,它将访问字符串STR的 第二个元素。
Program 2:
程式2:
#include <iostream>
using namespace std;
typedef struct{
int A;
char* STR;
} S;
int main()
{
S ob = { 10, "india" };
cout << sizeof(ob);
return 0;
}
Output:
输出:
In a 32-bit system: 8
In a 64-bit system: 16
Explanation:
说明:
Here, we created a structure with two members, one is an integer variable and another is a character pointer. We know that size of an integer is 4 bytes / 8 bytes and the size of any type of pointer is also 4 bytes / 8 bytes.
在这里,我们创建了一个具有两个成员的结构 ,一个是整数变量,另一个是字符指针。 我们知道整数的大小为4字节/ 8字节,任何类型的指针的大小也为4字节/ 8字节。
Program 3:
程式3:
#include <iostream>
using namespace std;
typedef struct{
int A;
int B;
char c1;
char c2;
} S;
int main()
{
cout << sizeof(S);
return 0;
}
Output:
输出:
In a 32-bit system: 12
In a 64-bit system: 24
Explanation:
说明:
Here, A and B will allocate two blocks of 4 bytes / 8 bytes, and normally character variable takes 1-byte memory space but due to structure padding c1 and c2 will take 1-1 byte and block is padded by remaining 2 bytes / 6 bytes. And then no other variable can use the padded space.
在这里, A和B将分配两个4字节/ 8字节的块,通常字符变量占用1字节的存储空间,但是由于结构填充, c1和c2将占用1-1字节,而块将由剩余的2字节/ 6填充个字节。 然后没有其他变量可以使用填充的空间。
1st block will store A, 2nd block will store B, and 3rd block will store c1, c2, and 2 bytes / 6 bytes space padding.
第一个块将存储A , 第二个块将存储B , 第三个块将存储c1, c2和2字节/ 6字节的空间填充。
Then the final size of the structure will be 12 / 24 bytes.
然后该结构的最终尺寸将是12 / 24-字节。
翻译自: https://www.includehelp.com/cpp-tutorial/structures-find-output-programs-set-2.aspx
c ++查找字符串
c ++查找字符串_C ++结构| 查找输出程序| 套装2相关推荐
- c ++查找字符串_C ++结构| 查找输出程序| 套装1
c ++查找字符串 Program 1: 程序1: #include <iostream> #include <math.h> using namespace std; str ...
- c ++查找字符串_C ++结构| 查找输出程序| 套装3
c ++查找字符串 Program 1: 程序1: #include <iostream> #pragma pack(1) using namespace std; typedef str ...
- c ++查找字符串_C ++数组| 查找输出程序| 套装5
c ++查找字符串 Program 1: 程序1: #include <iostream> using namespace std; int main() { char* STR[] = ...
- c ++查找字符串_C ++异常处理| 查找输出程序| 套装1
c ++查找字符串 Program 1: 程序1: #include <iostream> using namespace std; int main() { try { int num1 ...
- 查找字符串中要查找的字符串最后一次出现的位置
C++ Code 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 #include <stdio.h> #i ...
- c ++查找字符串_C ++类和对象| 查找输出程序| 套装4
c ++查找字符串 Program 1: 程序1: #include <iostream> using namespace std; class Sample { int X; int* ...
- c ++查找字符串_C ++类和对象| 查找输出程序| 套装3
c ++查找字符串 Program 1: 程序1: #include <iostream> using namespace std; class Sample { int X; publi ...
- c ++查找字符串_C ++类和对象| 查找输出程序| 套装5
c ++查找字符串 Program 1: 程序1: #include <iostream> using namespace std; class Sample { int X; int* ...
- c ++查找字符串_C ++类和对象| 查找输出程序| 套装1
c ++查找字符串 Program 1: 程序1: #include <iostream> using namespace std; class Sample { private int ...
最新文章
- SuperMap iDesktop Cross 8C 开源桌面GIS下载与扩展开发
- sdcms的模板解析引擎,一个非常简单和实用的CMS
- jsp uri=http://java.sun.com/jsp/jstl/core报错解决
- 新年第一战| 数字中国创新大赛·大数据赛道等你来战
- boost::geometry::intersection用法的测试程序
- 四则运算栈c语言程序,四则运算 
c语言编程
- NOI入门级数学: 数及其运算 数的进制之二进制
- 关键字nullable,nonnull,null_resettable,_Null_unspecified详解
- 机器学习,深度学习相关介绍
- win10中谷歌浏览器安装插件的位置
- halcon第六讲:基于颜色空间的颜色检测
- Tmall商品详情API接口
- Discuz app打包app上架appstore小技巧
- php 搜索关键字,PHP获取搜索关键字有关问题_PHP教程
- 如何利用UDP组播实现海康网络摄像机(IPC)的自动探测【源码】【监控】【录播】【NVR】【ONVIF】
- 基于B树的图书管理系统(C语言)(含完整代码)
- Python之保留小数点后n位、向上取整、向下取整以及四舍五入函数
- 零基础学习python数据分析,需要掌握哪些技能?
- IOS keychain 使用
- Windows版微信加密存储图片的解密工具GUI程序
热门文章
- python包mdure_Python hashlib模块实例使用详解
- 商场楼层导视牌图片_百宝图商场电子导视软件中预约产品功能简介
- 服务器修改地址,服务器修改管理地址
- html层次选择器例题,详解强大的jQuery选择器之基本选择器、层次选择器
- redis哨兵模式没有切换主机_Redis哨兵(Sentinel)模式
- 多核cpu应用场景_CPU占用100%!PC卡顿原来可以这么解决:多场景多任务也流畅
- html form callback,Promise异步编程模式总结初始化Promise对象统一错误处理PromisifyfromCallbackMongoose Promisify...
- 和push的区别_还没有理解let 和 const的用法和区别吗,几百字让你立马搞懂
- 前端架构设计1:代码核心
- 将不确定变为确定~头压缩是否有必要,MVC如何实现头压缩