日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

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

發布時間:2025/3/11 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 c ++查找字符串_C ++结构| 查找输出程序| 套装3 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

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的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。