产量 [英] output

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

问题描述

o / p这个什么都没有..你可以解释一下为什么......我知道它会与签名和未签名的东西有关...


#include< stdio.h>


#define TOTAL_ELEMENTS(sizeof(array)/ sizeof(array [0]))

int array [] = {23,34,12,17,204,99,16};


int main()

{

int d;

for(d = -1; d< =(TOTAL_ELEMENTS-2); d ++)

printf("%d \ n",array [d + 1]);


返回0;

}

解决方案

Abhishek Parwal写道:

o / p这个什么都没有..你可以解释为什么......我知道它会与签名和未签名的事情有关。

#include< stdio.h>

#define TOTAL_ELEMENTS(sizeof(array)/ sizeof(array [0]))
int array [] = {23,34 ,12,17,204,99,16};

int main()
{
int d;
for(d = -1; d< =( TOTAL_ELEMENTS-2); d ++)
printf("%d \ n",数组[d + 1]);

返回0;
}




请在发布前搜索档案,这个具体问题已经好几次讨论过


http://groups.google.com/group/comp....f96e862940333b
http://groups.google.com/group /comp....1a62b1532e620d
http://groups.google.com/group/comp....18e466cd0ae5c5

Robert Gamble


Abhishek Parwal写道:

o / p这是noth你可以解释为什么......我知道它会与签名和未签名有关...

#include< stdio.h>

#定义TOTAL_ELEMENTS(sizeof(array)/ sizeof(array [0]))
int array [] = {23,34,12,17,204,99,16};

int main(对于(d = -1; d< =(TOTAL_ELEMENTS-2); d ++)<<<<<<<<< sizeof是type size_t,而不是int
for(d = -1; d< =(int)(TOTAL_ELEMENTS-2); d ++)printf("%d \ n",array [d + 1] );

返回0;
}




所以这里,size_t似乎是无符号的,因此d被提升

未签名用于比较,-1是一个非常大的正数,

bit-wise。你也可以使用一点点缩进。此外,数组可以在main()中定义



-

- Mark


不,它与unsigned或signed无关,因为int是由

编译器默认采用签名(这可能是

实现依赖或编译依赖)。

你可以通过在声明前加上signed关键字来检查这个。


问题在于你的#define语句代码是

表达式。因此,它无法在for循环中与

变量d进行比较,从而导致无循环处理。


o/p of this is nothing .. can u explain why.. i know its gonna
something to do with signed and unsigned..

#include<stdio.h>

#define TOTAL_ELEMENTS (sizeof(array) / sizeof(array[0]))
int array[] = {23,34,12,17,204,99,16};

int main()
{
int d;
for(d=-1;d <=(TOTAL_ELEMENTS-2);d++)
printf("%d\n",array[d+1]);

return 0;
}

解决方案

Abhishek Parwal wrote:

o/p of this is nothing .. can u explain why.. i know its gonna
something to do with signed and unsigned..

#include<stdio.h>

#define TOTAL_ELEMENTS (sizeof(array) / sizeof(array[0]))
int array[] = {23,34,12,17,204,99,16};

int main()
{
int d;
for(d=-1;d <=(TOTAL_ELEMENTS-2);d++)
printf("%d\n",array[d+1]);

return 0;
}



Please search the archives before posting, this specific question has
been discussed several time before:

http://groups.google.com/group/comp....f96e862940333b
http://groups.google.com/group/comp....1a62b1532e620d
http://groups.google.com/group/comp....18e466cd0ae5c5

Robert Gamble


Abhishek Parwal wrote:

o/p of this is nothing .. can u explain why.. i know its gonna
something to do with signed and unsigned..

#include<stdio.h>

#define TOTAL_ELEMENTS (sizeof(array) / sizeof(array[0]))
int array[] = {23,34,12,17,204,99,16};

int main()
{
int d;
for(d=-1;d <=(TOTAL_ELEMENTS-2);d++) <<< sizeof is type size_t, not int for(d=-1;d <=(int) (TOTAL_ELEMENTS-2);d++) printf("%d\n",array[d+1]);

return 0;
}



So here, size_t appears to be unsigned thus ''d'' gets promoted to
unsigned for the comparison and -1 is a very big positive number,
bit-wise. You could use a little indenting too. Also, array can be
defined within main().
--
- Mark


No, it has nothing to do with the unsigned or signed because int is by
default taken by the compiler as signed ( this however maybe
implementation dependent or compile dependent).
You can check this by prefixing the declaration with signed keyword.

The problem lies with the # define statement in you code which is an
expression. Thereby it cannot be compared in the for loop with the
variable d, resulting in no loop processing.


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

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