Sizeof和增量运算符 [英] Sizeof and increment operators

查看:73
本文介绍了Sizeof和增量运算符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#include< stdio.h>


int main()

{

int number = 10;

printf(" Number is:%d \ n",number);


printf(" numberof sizeof:%d \ n" ;,sizeof(number ++));


printf(现在的数字是:%d \ n,数字);


返回0;

}

后增量运算符似乎不适用于此处。即使在调用sizeof运算符之后,

数字的值也保持不变。

有人可以澄清这个吗?


谢谢,

Anjali。

解决方案

g _ ******** @ rediffmail.com (Anjali M)写道:

printf(" numberof sizeof: %d \ n",sizeof(number ++));
后增量运算符似乎不适用于此处。即使在调用sizeof运算符之后,
数字的值也保持不变。
有人可以澄清这个吗?




从最后C99标准的公开草案,6.5.3.4#2:


#sizeof运算符...如果操作数的类型是可变长度

#array tye,操作数被评估;否则,操作数不是
#evaluate,结果是整数常量。


Richard


< blockquote>


sizeof运算符只返回一个或多个类型的大小,


所以我想,它没有定义为允许在其中进行美化操作。


再见,


Smitha


Anjali M <克_ ******** @ rediffmail.com>在留言中写道

news:99 ************************** @ posting.google.c om ...

#include< stdio.h>

int main()
{
int number = 10;
printf("编号为:%d \ n",number);

printf(" numberof sizeof:%d \ n",sizeof(number ++));

> printf(现在的数字是:%d \ n,数字);

返回0;
}

后增量运算符似乎没有在这里工作即使在调用sizeof运算符之后,
数字的值也保持不变。
有人可以澄清一下吗?

谢谢,
Anjali。


HI anjali,


Sizeof是C中的*运算符*

操作数sizeof中的预期值是一个标识符,它是一个表达式,或者是一个类型转换表达式(即括号中的类型说明符

)。一元表达式不能代表一个

位字段对象,一个不完整类型或一个函数指示符。


一元表达式是一个表达式,其估值是由

计算,将其(一元)运算符应用于其操作数的估值。有三种一元运算符:

(1)逻辑补语一元运算符!,

(2)加上一元运算符+,和

(3)减去一元运算符 - " ;.


希望这有助于


sumukh

Anjali M写道:

#include< stdio.h>

int main()
{
int number = 10;
printf(" Number is:%d \ n",number);

printf("数字的大小是:%d \ n",sizeof(数字++));

printf(现在的数字是:%d \ n,数字);

返回0;
}

后增量运算符似乎不适用于此处。即使在调用sizeof运算符之后,
数字的值也保持不变。
有人可以澄清一下吗?

谢谢,
Anjali。


#include <stdio.h>

int main()
{
int number = 10;
printf("Number is: %d\n", number);

printf("Sizeof of number is: %d\n", sizeof(number++));

printf("Number now is: %d\n", number);

return 0;
}
The post-increment operator doesnt seem to work here. The value of the
number remains the same even after the call to the sizeof operator.
Can someone clarify this please?

Thanks,
Anjali.

解决方案

g_********@rediffmail.com (Anjali M) wrote:

printf("Sizeof of number is: %d\n", sizeof(number++)); The post-increment operator doesnt seem to work here. The value of the
number remains the same even after the call to the sizeof operator.
Can someone clarify this please?



From the last public draft of the C99 Standard, 6.5.3.4#2:

# The sizeof operator... If the type of the operand is a variable length
# array tye, the operand is evaluated; otherwise, the operand is not
# evaluated and the result is an integer constant.

Richard


Hi,

The sizeof operator just returns the size of the type or expressions,

so i guess,it is not defined to allow airthmetic operations within it.

Bye,

Smitha

"Anjali M" <g_********@rediffmail.com> wrote in message
news:99**************************@posting.google.c om...

#include <stdio.h>

int main()
{
int number = 10;
printf("Number is: %d\n", number);

printf("Sizeof of number is: %d\n", sizeof(number++));

printf("Number now is: %d\n", number);

return 0;
}
The post-increment operator doesnt seem to work here. The value of the
number remains the same even after the call to the sizeof operator.
Can someone clarify this please?

Thanks,
Anjali.



HI anjali,

Sizeof is an *operator* in C.
The operand expected in sizeof is either an identifier that is a
unary-expression, or a type-cast expression (that is, a type specifier
enclosed in parentheses). The unary-expression cannot represent a
bit-field object, an incomplete type, or a function designator.

A unary expression is an expression whose valuation is computed by
applying its (unary) operator to the valuation of its operand. There are
three kinds of unary operators:
(1) the logical complement unary operator "!",
(2) the plus unary operator "+", and
(3) the minus unary operator "-".

Hope this helps

sumukh
Anjali M wrote:

#include <stdio.h>

int main()
{
int number = 10;
printf("Number is: %d\n", number);

printf("Sizeof of number is: %d\n", sizeof(number++));

printf("Number now is: %d\n", number);

return 0;
}
The post-increment operator doesnt seem to work here. The value of the
number remains the same even after the call to the sizeof operator.
Can someone clarify this please?

Thanks,
Anjali.



这篇关于Sizeof和增量运算符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆