c ++查找字符串

Program 1:

程序1:

#include <iostream>
#pragma pack(1)
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: 10
In a 64-bit system: 18

Explanation:

说明:

We compiled the program on a 32-bit system. It will print "10" on the console screen.

我们在32位系统上编译了该程序。 它将在控制台屏幕上打印“ 10”

Normally, the above program will print "12" due to structure padding. But, here, we used #pragma pack(1) directives. It is used to avoid the structure padding. Then the size of the above structure will be "10".

通常,由于结构填充,上述程序将打印“ 12” 。 但是,在这里,我们使用了#pragma pack(1)指令。 用于避免结构填充。 那么上述结构的大小将为“ 10”

Program 2:

程式2:

#include <iostream>
using namespace std;
struct st {
char c1;
int A;
int B;
char c2;
};
int main()
{
struct st* ptr;
cout << sizeof(ptr);
return 0;
}

Output:

输出:

In a 32-bit system: 4
In a 64-bit system: 8

Explanation:

说明:

We compiled this program on a 32-bit system.

我们在32位系统上编译了该程序。

Here, we created a structure with 4 members, and a pointer to the structure.

在这里,我们创建了一个具有4个成员的结构 ,以及一个指向该结构的指针。

cout<<sizeof(ptr);

The above statement will print "4". Because, the size of any type of pointer in a 32-bit system is 4 bytes.

上面的语句将打印“ 4 ”。 因为,在32位系统中,任何类型的指针的大小均为4个字节。

Program 3:

程式3:

#include <iostream>
using namespace std;
struct st {
char c1;
int A;
int B;
char c2;
};
int main()
{
struct st ob;
struct st* ptr = &ob;
cout << sizeof(*ptr);
return 0;
}

Output:

输出:

16

Explanation:

说明:

We compiled the program on 32-bit based system.

我们在基于32位的系统上编译了该程序。

Here, we created a structure, C++ uses structure padding and allocate space for variables block-wise, block size is 4 bytes for 32-bit based system.

在这里,我们创建了一个结构,C ++使用结构填充并按块逐个分配变量,对于基于32位的系统,块大小为4个字节。

In the main() function we created a structure variable ob, and a pointer ptr that contains the address of ob.

main()函数,我们创建了一个结构变量的ob和包含OB的地址的指针PTR。

cout<<sizeof(*ptr);

The above statement will print the size of the structure.

上面的语句将打印结构的大小。

1st block is allocated for c1 that is 4 bytes.
2nd block is allocated for A that is 4 bytes.
3rd block is allocated for B that is 4 bytes.
4th block is allocated for c2 that is 4 bytes.

Then, the total size is "16" bytes will be printed on the console screen.

然后,总大小为“ 16”字节将被打印在控制台屏幕上。

翻译自: https://www.includehelp.com/cpp-tutorial/structures-find-output-programs-set-3.aspx

c ++查找字符串

c ++查找字符串_C ++结构| 查找输出程序| 套装3相关推荐

  1. c ++查找字符串_C ++结构| 查找输出程序| 套装2

    c ++查找字符串 Program 1: 程序1: #include <iostream> using namespace std; int main() { typedef struct ...

  2. c ++查找字符串_C ++结构| 查找输出程序| 套装1

    c ++查找字符串 Program 1: 程序1: #include <iostream> #include <math.h> using namespace std; str ...

  3. c ++查找字符串_C ++数组| 查找输出程序| 套装5

    c ++查找字符串 Program 1: 程序1: #include <iostream> using namespace std; int main() { char* STR[] = ...

  4. c ++查找字符串_C ++异常处理| 查找输出程序| 套装1

    c ++查找字符串 Program 1: 程序1: #include <iostream> using namespace std; int main() { try { int num1 ...

  5. 查找字符串中要查找的字符串最后一次出现的位置

    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 ...

  6. c ++查找字符串_C ++类和对象| 查找输出程序| 套装4

    c ++查找字符串 Program 1: 程序1: #include <iostream> using namespace std; class Sample { int X; int* ...

  7. c ++查找字符串_C ++类和对象| 查找输出程序| 套装3

    c ++查找字符串 Program 1: 程序1: #include <iostream> using namespace std; class Sample { int X; publi ...

  8. c ++查找字符串_C ++类和对象| 查找输出程序| 套装5

    c ++查找字符串 Program 1: 程序1: #include <iostream> using namespace std; class Sample { int X; int* ...

  9. c ++查找字符串_C ++类和对象| 查找输出程序| 套装1

    c ++查找字符串 Program 1: 程序1: #include <iostream> using namespace std; class Sample { private int ...

最新文章

  1. 读样章、写评语,即有机会获赠《编程大师访谈录》!
  2. svn中提示”Files 的值 .mine 无效” 的解决方案
  3. mysql在没有任何用户的情况下,如何恢复
  4. 服务端监控要怎么做?
  5. 学生机房管理服务器系统设计,广东工业大学数据库课程设计机房管理系统设计...
  6. modelsim 编译 xilinx库
  7. 安装配置 radicale
  8. @async 如何返回list_图解 Await 和 Async
  9. oracle 没有索引删除一行数据_Oracle数据库之索引
  10. java读文件几种方式_java中读取文件的方式有哪几种
  11. mysql 查询最早 表,【MySQL】MySQL查询表的创建时间
  12. [深大深鸿会]利用DevEco Studio从零开发OpenHarmony小游戏——2048(下)
  13. 怎样在word表格中快速输入序号?
  14. 电容在计算机运用原理,隔直电容的作用及原理 - 全文
  15. 位置度标注方法图解_追踪主力-散户操盘实战图解:案例实操
  16. java.sql.BatchUpdateException
  17. 二阶可导的充要条件_可导函数在x
  18. 华为OD机试真题 Java 实现【猜字谜】【2023Q1 100分】
  19. 第一行代码——Android pdf
  20. 电子元器件:三极管参数笔记(持续记录)

热门文章

  1. HTML4基本编译原理,Stanford公开课《编译原理》学习笔记(1~4课)
  2. Qt图形界面编程入门(标签与槽机制习题分享)
  3. html 拖拽坐标,Html+css实现拖拽导航条
  4. opencv获取模板旋转角度_OpenCV入门之获取图像的旋转角度
  5. Digit sum【暴力+打表】
  6. UVA1225 ​​​​​​​Digit Counting
  7. 转:6.1海量数据处理
  8. linux升级python
  9. android四大组件之Service 注册广播接收者
  10. 堆和栈、值类型与引用类型、装箱与拆箱