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 ++查找字符串

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/544846.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

7种内存泄露场景和13种解决方案!

前言Java通过垃圾回收机制&#xff0c;可以自动的管理内存&#xff0c;这对开发人员来说是多么美好的事啊。但垃圾回收器并不是万能的&#xff0c;它能够处理大部分场景下的内存清理、内存泄露以及内存优化。但它也并不是万能的。不然&#xff0c;我们在实践的过程中也不会出现…

Android如何关闭Application

转载自&#xff1a;http://blog.csdn.net/hello_kevinkuang/article/details/7443005 程序启动后&#xff0c;先执行Application.onCreate()&#xff0c;再执行Activity.onCreate()。如果没有生成自己的Application&#xff0c;那么系统会为你自动生成一个。退出程序时我们一般…

Android Sqlite

2019独角兽企业重金招聘Python工程师标准>>> 一、http://lansuiyun.iteye.com/blog/1246430 good! 二、增加新表时&#xff0c;需要更新版本号。 三、Android 使用自定义cursorAdapter&#xff1a; http://blog.csdn.net/buaalei/article/details/6064792 good! 四…

优雅统计代码耗时的4种方法!

来源&#xff1a;jitwxs.cn/5aa91d10.html一、前言代码耗时统计在日常开发中算是一个十分常见的需求&#xff0c;特别是在需要找出代码性能瓶颈时。可能也是受限于 Java 的语言特性&#xff0c;总觉得代码写起来不够优雅&#xff0c;大量的耗时统计代码&#xff0c;干扰了业务逻…

小黑小波比.git clone报错解决方案

2019独角兽企业重金招聘Python工程师标准>>> zmzpzmzp1:~/data$ git clone git192.168.199.199:zmw/s910.git 正克隆到 s910... ssh: connect to host 192.168.199.199 port 22: Connection refused fatal: Could not read from remote repository.Please make sure…

Android 运行时异常 Binary XML file line # : Error inflating class

今天在做一个二维码扫描的项目的时候出现了一个错误&#xff1a; android.view.InflateException: Binary XML file line #12: Error inflating class com.zxing.view.ViewfinderView 项目里面的代码是我从以前项目里面拷贝的&#xff0c;可是各种报错&#xff0c;找了很多资…

一个sql注入直接把我们服务搞挂了

前言最近我在整理安全漏洞相关问题&#xff0c;准备在公司做一次分享。恰好&#xff0c;这段时间团队发现了一个sql注入漏洞&#xff1a;在一个公共的分页功能中&#xff0c;排序字段作为入参&#xff0c;前端页面可以自定义。在分页sql的mybatis mapper.xml中&#xff0c;orde…

reinterpret_cast和static_cast的总结

主要参考&#xff1a;http://blog.csdn.net/querw/article/details/7387594 http://www.cnblogs.com/jerry19880126/archive/2012/08/14/2638192.html http://www.cnblogs.com/ider/archive/2011/07/30/cpp_cast_operator_part3.htmlhttp://bbs.csdn.net/topics/390249118 关键…

Android实现点击两次返回键退出

转自 http://blog.sina.com.cn/s/blog_4fd2a65a0101gg2o.html 在做安卓应用是我们经常要判断用户对返回键的操作&#xff0c;一般为了防止误操作都是在用户连续按下两次返回键的时候提示用户是否退出应用程序。 第一种实现的基本原理就是&#xff0c;当按下BACK键时&#xff0c…

c#hello world_C#| 打印消息/文本(用于打印Hello world的程序)

c#hello worldTo print the message/text or any value – we use two functions: 要打印消息/文本或任何值–我们使用两个功能&#xff1a; Console.Write (); Console.Write(); This function displays text, values on the output device and does not insert a new line …

Java双刃剑之Unsafe类详解

前一段时间在研究juc源码的时候&#xff0c;发现在很多工具类中都调用了一个Unsafe类中的方法&#xff0c;出于好奇就想要研究一下这个类到底有什么作用&#xff0c;于是先查阅了一些资料&#xff0c;一查不要紧&#xff0c;很多资料中对Unsafe的态度都是这样的画风&#xff1a…

Java知多少(66)输入输出(IO)和流的概述

输入输出&#xff08;I/O&#xff09;是指程序与外部设备或其他计算机进行交互的操作。几乎所有的程序都具有输入与输出操作&#xff0c;如从键盘上读取数据&#xff0c;从本地或网络上的文件读取数据或写入数据等。通过输入和输出操作可以从外界接收信息&#xff0c;或者是把信…

单行 - JAVA 条件表达式

public class ExpressionUse{//It’s the main() function.//每个应用程序都应该有一个main()函数体。public static void main(String[] args){int a10;int b1;int c(a<b)?a:b;System.out.println("a"a);System.out.println("b"b);System.out.println…

额!Java中用户线程和守护线程区别这么大?

作者 | 王磊来源 | Java中文社群&#xff08;ID&#xff1a;javacn666&#xff09;转载请联系授权&#xff08;微信ID&#xff1a;GG_Stone&#xff09;在 Java 语言中线程分为两类&#xff1a;用户线程和守护线程&#xff0c;而二者之间的区别却鲜有人知&#xff0c;所以本文磊…

c++中int向量初始化_以不同的方式在C ++中初始化2D向量

c中int向量初始化Prerequisite: Initialize 1D vector 先决条件&#xff1a; 初始化一维向量 Before discussing about the initialization techniques let us state what a 2D vector is. A 2D vector in simple sense is a matrix having rows and column. In other words, …

EasyUI-右键菜单变灰不可用效果

使用过EasyUI的朋友想必都知道疯狂秀才写的后台界面吧&#xff0c;作为一个初学者我不敢妄自评论它的好坏&#xff0c;不过它确实给我们提供了一个很好框架&#xff0c;只要在它的基础上进行修改&#xff0c;基本上都可以满足我们开发的需要。 知道“疯狂秀才”写的后台界面已经…

Oracle中insert into select和select into的区别

文章转自&#xff1a;http://www.linuxidc.com/Linux/2012-09/70984.htm 在Oracle中&#xff0c;将一张表的数据复制到另外一个对象中。通常会有这两种方法&#xff1a;insert into select 和 select into from。 前者可以将select 出来的N行(0到任意数)结果集复制一个新表中…

ThreadLocal中的3个大坑,内存泄露都是小儿科!

我在参加Code Review的时候不止一次听到有同学说&#xff1a;我写的这个上下文工具没问题&#xff0c;在线上跑了好久了。其实这种想法是有问题的&#xff0c;ThreadLocal写错难&#xff0c;但是用错就很容易&#xff0c;本文将会详细总结ThreadLocal容易用错的三个坑&#xff…

java中为按钮添加图片_如何在Java中为字符串添加双引号?

java中为按钮添加图片In Java, everything written in double-quotes is considered a string and the text written in double-quotes is display as it is. 在Java中&#xff0c; 双引号中的所有内容均视为字符串&#xff0c;而双引号中的文本按原样显示。 Suppose, if we wa…

基于.Net的单点登录(SSO)解决方案

为什么80%的码农都做不了架构师&#xff1f;>>> 前些天一位朋友要我帮忙做一单点登录&#xff0c;其实这个概念早已耳熟能详&#xff0c;但实际应用很少&#xff0c;难得最近轻闲&#xff0c;于是决定通过本文来详细描述一个SSO解决方案&#xff0c;希望对 大家有所…