c语言的sizeof到底应该返回什么?

一步步教你使用 NVIDIA 推出的全新GPU加速求解器 cuOpt:解锁超高效率的求解体验 未完成 阅读详情

我发现这个面试问题难住了蛮多人的。总的来说,sizeof(x)返回的是该值x占用的存储空间的大小。但是,问题就出在这个"x"到底是啥?

#include <stdio.h>
#include <string.h>
#define HELLO_STR "hello"
#define HELLO_STR2 "hello\0"

int hello(int input[3][3])
{
    printf("the sizeof(input) is: %d\n",sizeof(input));
}

int main(int argc, char *argv[])
{
    int i = 0;
    int j[10];
    char x[3][3];
    char str[] = "aBcDefghijklmn";
    printf("the sizeof(1) is: %d\n",sizeof(1));
    printf("the sizeof(i) is: %d\n",sizeof(i));
    printf("the sizeof(&i) is: %d\n",sizeof(&i));
    printf("the sizeof(j) is: %d\n",sizeof(j));
    printf("the sizeof(&j) is: %d\n",sizeof(&j));
    printf("the sizeof(x) is: %d\n",sizeof(x));
    printf("the sizeof(str[]) is:%d\n", sizeof(str));
    printf("the strlen(str[]) is:%d\n", strlen(str));
    printf("the sizeof(&str[]) is:%d\n", sizeof(&str));
    printf("the sizeof(HELLO_STR) is: %d\n",sizeof(HELLO_STR));
    printf("the sizeof(HELLO_STR2) is: %d\n",sizeof(HELLO_STR2));
    printf("the strlen(HELLO_STR) is: %d\n",strlen(HELLO_STR));
    printf("the strlen(HELLO_STR2) is: %d\n",strlen(HELLO_STR2));
    hello(j);
    return 0;
}


以下面的代码为例,有多少人能正确写出所有的结果呢?

在我的mac上,输出的结果是这样的

the sizeof(1) is: 4
the sizeof(i) is: 4
the sizeof(&i) is: 8
the sizeof(j) is: 40
the sizeof(&j) is: 8
the sizeof(x) is: 9
the sizeof(str[]) is:15
the strlen(str[]) is:14
the sizeof(&str[]) is:8
the sizeof(HELLO_STR) is: 6
the sizeof(HELLO_STR2) is: 7
the strlen(HELLO_STR) is: 5
the strlen(HELLO_STR2) is: 5
the sizeof(input) is: 8

1是一个int型,输出4,很好理解。

i是int型,输出4,也好理解。

&i是一个指针,我的mac是64位的,返回8,也好说。

j是一个int数组,占用的空间是4 * 10,返回40。

&j是一个指针,同&i

HELLO_STR,这个其实有点意思,他是被优化过的,返回了6,可以看到我的编译器给他自动append了一个 '\0',strlen(HELLO_STR)应该返回5。

HELLO_STR2同上,也是append了'\0'。这个行为有点编译器优化的意思,因为在部分嵌入式的编译器,这个返回实际上跟strlen是相同的,所以具体一个define是返回多少,有点看编译器。

x的size是9,也好说,矩阵是3*3的,char的空间是9

str这个网上有人说这个是动态数组,返回的应该是指针大小,但是我实际测试,发现还是指向的数据空间的大小。so,返回的是15

str的strlen结果,没得说,14,很直接。

&str没得说,指针的大小。这里是8

最后的input,就有意思了,为什么是8呢?因为虽然函数定义是input[3][3],但是实际传入到函数的是一个int指针,指针,返回指针的大小。

再挖深点,谈谈编译器优化

实际上,大家都知道,c是静态语言,所以sizeof完全是可以在编译过程中计算好的。我在linux下对代码进行了简单的反编译(mac的汇编格式实在不习惯。。。),就可以看到,没个printf的调用,都是这样的一段:

  0x00000000004006c1 <+312>:	mov    $0x40092c,%eax
   0x00000000004006c6 <+317>:	mov    $0x6,%esi
   0x00000000004006cb <+322>:	mov    %rax,%rdi
   0x00000000004006ce <+325>:	mov    $0x0,%eax
   0x00000000004006d3 <+330>:	callq  0x400460 <printf@plt>

这里eax的值是格式化字符串的地址,esi的值是6,也就是直接算出来的sizeof结果。有兴趣的可以自己看看。

但是纵观反编译的结果,只有调用printf的callq,没有调用strlen的。进一步观察,发现实际上部分strlen也被提前计算了。

   0x0000000000400706 <+381>:	mov    $0x400970,%eax
   0x000000000040070b <+386>:	mov    $0x5,%esi
   0x0000000000400710 <+391>:	mov    %rax,%rdi
   0x0000000000400713 <+394>:	mov    $0x0,%eax
   0x0000000000400718 <+399>:	callq  0x400460 <printf@plt>

看来对于常量字符串,编译器会进一步优化,预计算这个strlen。但是有一个有意的,就是str数组,是个动态数组,也会被优化嘛?追踪了本地的strlen实现,发现这个strlen被展开了,使用了一个repnz scas来实现。具体代码如下:

   0x000000000040066e <+229>:	lea    -0x20(%rbp),%rax
   0x0000000000400672 <+233>:	movq   $0xffffffffffffffff,-0x78(%rbp)
   0x000000000040067a <+241>:	mov    %rax,%rdx
   0x000000000040067d <+244>:	mov    $0x0,%eax
   0x0000000000400682 <+249>:	mov    -0x78(%rbp),%rcx
   0x0000000000400686 <+253>:	mov    %rdx,%rdi
   0x0000000000400689 <+256>:	repnz scas %es:(%rdi),%al
   0x000000000040068b <+258>:	mov    %rcx,%rax
   0x000000000040068e <+261>:	not    %rax
   0x0000000000400691 <+264>:	lea    -0x1(%rax),%rdx
   0x0000000000400695 <+268>:	mov    $0x4008f9,%eax
   0x000000000040069a <+273>:	mov    %rdx,%rsi
   0x000000000040069d <+276>:	mov    %rax,%rdi
   0x00000000004006a0 <+279>:	mov    $0x0,%eax
   0x00000000004006a5 <+284>:	callq  0x400460 <printf@plt>

scas指令的全称为scan a string,具体内容有兴趣的可以参考 这个问题

so,一个看似简单的sizeof和strlen,还是有很多有意思的事情的。


使用 Fargate 在 AWS ECS 上运行 Spring Boot 应用程序 本文介绍了使用AWS Fargate支持的ECS部署SpringBoot应用的完整流程。主要内容包括:1)将SpringBoot应用打包为Docker镜像并推送至ECR;2)创建任务定义配置CPU、内存和网络等参数;3)设置ECS服务管理任务运行;4)配置负载均衡器分配流量;5)设计VPC网络和安全组规则确保安全访问;6)使用SSM参数存储管理敏感信息。整个过程实现了无服务器化部署,既保持了应用控制权,又免除了基础设施管理负担,是扩展Web服务的可靠方案。 阅读详情

相关推荐

PPPoE上网配置不求人:华为路由器命令行操作指南(2023最新版)

本文提供2023年最新的华为路由器PPPoE上网配置命令行操作指南。通过详细的步骤讲解,从连接设备、创建拨号接口、绑定PPPoE客户端到配置内网与NAT,手把手教你完成配置,并附有验证排错方法,助你轻松实现稳定上网。

s4t5u6v的博客 684

sizeof操作符详解一

更多精彩内容,请见:http://www.16boke.com by zxy,Java/C++编程交流群:168424095 讨论及测试基础是Windows 32位平台,VS2008开发工具: 测试基本类型 1.基本规则 sizeof 操作符的作用是返回一个对象或类型名所占的内存字节数,返回值的类型为size_t,长度的单位是字节,在编译而不是运行时确定。 • 对引用类型做sizeof操作将返回存放此引用类型对象所需的内在空间大小

踏踏实实的。。。 3037

管道机器人手臂机械结构设计cad【8张】+三维图+设计说明书+绛重

履带式管道机器人适用于各种管道环境,包括直管道、弯曲管道、水平管道、垂直管道等,其灵活性和适应性使得它可以应对不同形状和尺寸的管道,完成全面的检测和维护工作。管道机器人研究具有重要的现实意义和深远的社会影响,通过提高工作效率、降低人员风险、提升服务质量、节约成本资源和促进科技创新等方面的作用,为现代工程技术领域的发展和进步做出了积极的贡献。管道机器人是一种能够在管道内部执行各种任务的智能机器人,而管道机器人的机械臂对于管道机器人在管道内执行任务的灵活性、稳定性和效率至关重要。

kejigongjiang的博客 950

C/C++ :Sizeof 的用法

Sizeof有以下特点: Sizeof是C/C++中的一个运算符,不是一个函数,返回值为size_t sizeof不能被编译成机器码,编译过程中就会计算sizeof的具体值,然后用值替换掉sizeof ()。所以可以用sizeof() 来定义数组的维数。 sizeof ()里面的内容也不能被编译,而是被替换成类型。 sizeof 后面可以直接加变量名,不用加();sizeof一个类型时,必...

zgcjaxj的博客 4714

保姆级教程:在Linux上用IGH EtherCAT主站搞定从站时钟同步(附sync_datagram报文详解)

本文详细介绍了在Linux系统上使用IGH EtherCAT主站实现从站时钟同步的保姆级教程,重点解析了sync_datagram报文的结构和工作原理。通过实战案例和代码示例,帮助开发者掌握微秒级同步精度的实现方法,适用于工业自动化领域的高精度设备协同控制。

weixin_30733003的博客 264

『与善仁』Appium基础 — 19、元素定位工具之UI Automator Viewer

文章目录(一)uiautomatorviewer定位工具1、uiautomatorviewer介绍2、uiautomatorviewer工具打开方式3、uiautomatorviewer布局介绍4、uiautomatorviewer工具的使用 之前我们在做web页面自动化的时候就说过,元素定位是页面自动化的第一步。 同理App自动化测试的第一步,也是元素的定位。 在APP中定位元素的话,需要借助一些元素定位工具。 APP中的元素定位工具大致有三种: uiautomatorviewer Appium Ins

繁华似锦Fighting 1522

说说 sizeof

sizeof 虽说简单,但往往在一些细节上面容易出错

ameth 1091

【PVCodeNet】《Palm Vein Recognition Network Combining Transformer and CNN》

1]吴凯,沈文忠,贾丁丁,等.融合Transformer和CNN的手掌静脉识别网络[J].计算机工程与应用,2023,59(24):98-109.

bryant_meng 1283

C语言:关于sizeof返回值的理解

我学指针的时候发现,64位编译会出现如下情况,(当时百思不得其解,通过百度,问大佬总结以下几点): 1.运算符 sizeof 的返回值是 unsigned 类型,x 是 int 类型,比较时会将 x 升级为 unsigned 类型,而 -1 变为 unsigned 类型是一个很大的整数。 2、sizeof操作符能够得到一个结构的整体长度,包括因边界对齐而跳过的那些字节。 3、sizeof 和 s...

Specif1c的博客 1万+

【71页PPT】工业40及智能制造解决方案(附下载方式)

2013年,工业4.0平台发布白皮书,正式确立其发展战略。工业4.0不仅是技术的升级,更是制造业思维的重构。工业4.0的核心是通过信息物理系统(CPS)实现工厂内外的互联,构建高度灵活的个性化生产模式。它不仅是技术革新,更是一种生产方式的变革,使传统行业界限模糊化,催生新的商业模式和合作形式。德国作为制造业强国,其GDP的25%和出口总额的60%依赖制造业,因此工业4.0成为其维持全球领先地位的重要战略。CPS是工业4.0的基石,通过计算、通信与控制技术(3C)实现物理世界与信息世界的深度融合。

2501_92808811的博客 951

用Python+Charles搞定小程序付费短剧下载(附完整代码与避坑点)

本文详细介绍了如何利用Python和Charles抓包工具实现小程序付费短剧的自动化下载。通过分析小程序视频接口、破解请求参数,并编写Python脚本,读者可以轻松获取并保存短剧内容。文章还提供了完整的代码示例和常见问题的解决方案,特别适合对视频采集和抓包技术感兴趣的开发者。

weixin_28731231的博客 1194

C语言 sizeof()用法介绍

1.定义 sizeof是一个操作符(operator)。 其作用是返回一个对象或类型所占的内存字节数。 2.语法 sizeof有三种语法形式: 1)sizeof (object);//sizeof (对象) 2)sizeof object;//sizeof对象 3)sizeof (type_name);//sizeof (类型) 对象可以是各种类型的变量,以及表达式(一般sizeof不会对表达式进行计算)。 sizeof对对象求内存大...

eli的博客 1440

Unlocking Decoding-time Controllability: Gradient-FreeMulti-Objective Alignment with Contrastive Pr

将基于庞大网络语料库训练的大型语言模型(LLMs)(OpenAI,2023;Touvron 等,2023;Google,2023)与人类偏好对齐,是减少产生不安全(Wei 等,2023)、幻觉(Zhang 等,2023b)和有偏见(Gallegos 等,2023)内容的重要一步。随着偏好学习技术(如 PPO(Schulman 等,2017)、DPO(Rafailov 等,2023)及其他变体(Azar 等,2023;Ethayarajh 等,2024;

qq_52053775的博客 1169

c语言sizeof返回数据类型,sizeof函数返回值类型

#include int main(void) { printf("type int has a size of (1)sizeof不是函数,它只是一个操作符(operator)。 (2)sizeof的作用是返回一个对象或者类型所占的内存字节数,它的返回值的类型是size_t类型,而size_t是在头文件stddef.h中定义的。size_t 这是一个依赖于编译系统的值。C语言中,sizeof返...

weixin_36364248的博客 6858

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

c语言 sizeof在哪个库,c语言的sizeof到底应该返回什么?

我发现这个面试问题难住了蛮多人的。总的来说,sizeof(x)返回的是该值x占用的存储空间的大小。但是,问题就出在这个"x"到底是啥?#include #include #define HELLO_STR "hello"#define HELLO_STR2 "hello\0"int hello(int input[3][3]){printf("the sizeof(input) is: %d\n"...

weixin_36232899的博客 1149

VB摄像头监控

该VB模块可对摄像头捕获的画面进行录像等,可在创建的窗口进行控制

C语言sizeof记 0,C ++-sizeof可以返回0(零)

C ++-sizeof可以返回0(零)sizeof运算符是否有可能在C或C ++中返回0(零)? 如果有可能,从标准角度来看是否正确?TheJuice asked 2020-01-28T20:47:38Z10个解决方案40 votes在C ++中,根据定义,空类或结构的char至少为1。 从C ++标准的9/3“类”:“类类型的完整对象和成员子对象应具有非零大小。”在C语言中,除扩展名(或编译器中...

weixin_33816047的博客 1240

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

<c语言学习> sizeof 返回的类型是啥?为啥用%zd作为占位符

d 是int整形的占位符 , %zd 是vs 环境下的独特占位符;sizeof 返回值类型是 size_t;size_t 是无符号整形 ,至于是长整形还是短整形,每个编译器定义的不同;在vs环境里 ,size_t类型数据的占位符是%zd。

weixin_46571256的博客 2016

C语言---sizeof运算符的返回类型

1、sizeof 运算符返回的是一个 unsigned 类型 #include<stdio.h> int array_table[6]={12,14,15,35}; #define LEN (sizeof(array_table)/sizeof(array_table[0])) int main(void) { int x=-1; if(x<=LEN...

tyustli 1万+

c语言sizeof 5的值是,C语言中,sizeof返回值代表什么意思?

满意答案h9xzv5137推荐于 2017.09.07采纳率:42%等级:12已帮助:8880人sizeof是C/C++中的一个操作符(operator),作用就是返回一个对象或者类型所占的内存字节数。返回值类型为size_t,在头文件stddef.h中定义这是一个依赖于编译系统的值,一般定义为typedef unsigned int size_t;编译器林林总总,但作为一个规范,都会保证...

weixin_32334209的博客 1018

C语言中输出sizeof的返回值

sizeof()运算符的值的类型是size_t而不是int,所以不能用用于int的%d。 如果使用C99标准,则需要包含头文件:#include 或 #include 对应的格式化控制符应该使用 %zu

随波一落叶 5263

C语言关于sizeof和函数返回的若干问题(小白中~~)

注意点一: 这个函数得到的结果是 80 8 8 41 2 这告诉我们同样是sizeof(),指针和数组输出效果不同。 当b是数组时sizeof(b)为数组的内存空间大小,这里是20*4bit; 而当arr是指针时,sizeof(arr)仅表示一个地址的内存空间大小,即8bit。 这是一种效率的体现,只要传递首个数组的地址,就能传递整个数组 注意点二 这个程序会产生warning。原因是数组c[10]是放在栈(stack)中的,当该function函数结束后,该数组的空间就被释放了,再用于main函数中属于

dakerbose的博客 507

C 语言sizeof 在Visual Studio 中返回值大小

1、近日调试过程中,32位机 发现在VS 2012中,程序代码中对同一个字符串sizeof的返回值大小在代码中和监视中不一致,尚有疑惑,作下记录。C语言中字符串常量分配到可读数据区。 char a[] = "0123456789"; sizeof(a) /* 11,*/ sizeof("0123456789") /* 11,*/ 但是如上图所示中的监视窗口中 看到的sizeof...

pengbowen218的专栏 1186

c语言sizeof返回数据类型,C语言---sizeof运算符的返回类型

1、sizeof 运算符返回的是一个 unsigned 类型#includeint array_table[6]={12,14,15,35};#define LEN (sizeof(array_table)/sizeof(array_table[0]))int main(void){int x=-1;if(x<=LEN)printf("can be printfed!!!! ");elsep...

weixin_36447301的博客 1131

c语言中 sizeof返回的是无符号,C/C++中的sizeof运算符和size_t类型的详解

sizeof的作用sizeof是c的运算符之一,用于获取操作数被分配的内存空间,以字节单位表示.这里指的操作数,可以是变量,也可以是数据类型,如int,float等.所以就可以通过它来获取本地c库定义的基本类型的范围。sizeof的使用1.对于一般变量,形式2种:sizeof a 或 sizeof(a);2.对于数据类型,必须使用带括号的方式,如sizeof(int).size_t的说明size_...

weixin_34392511的博客 1372

C语言 - sizeof() 各种返回值 实例讲解

// 谁能帮我注释下,留言即可,thanks!#include #include #include int main(void){int a[4];printf("%d\n", sizeof(a)); //16printf("%d\n", sizeof(int [4])); //16printf("%d\n", sizeof(int * [4])); //16printf("%d\n",

W_Jp - 编程爱好者 1422

(C语言)sizeof()返回占据的字节数

(C语言)sizeof()返回占据的字节数

qq_43118674的博客 194
上一篇: TCP三次握手的第三个ack丢了会怎样
下一篇: 一篇文章搞懂c语言常量与指针的几个排列组合
john-zeng
博客等级 码龄16年 44粉丝 47原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值