如何确定int是否没有值 [英] How to find out if an int has no value

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

问题描述

在我想到这些问题之前我已经尝试过这个问题了。

这个问题。这是一件很简单的事情,但它让我疯了!

是否可以检查int(或任何其他类型)是否没有价值。

类似于:


int i;

...

...

...

if(i == NULL){

......

}


我知道这不起作用,我知道NULL是一个指针。有没有办法

这可以吗?

TIA。

解决方案

Richard< ; RI ************** @ hotmail.com>潦草地写着以下内容:

在我想到这些问题之前,我已经尝试过这个问题了。这是一件很简单的事情,但它让我疯了!
是否有可能检查int(或任何其他类型)是否没有价值。
类似于:



标量类型(如整数)总是有值。因此你的问题

没有意义。


-

/ - Joona Palaste(pa ***** @ cc.helsinki.fi)-------------芬兰-------- \

\-- http://www.helsinki.fi/~palaste ------------ ---------规则! -------- /

人类中的孤雌生殖将导致建立一个新的宗教信仰。

- John Nordberg


Joona I Palaste< pa ***** @ cc.helsinki.fi>写在

新闻:ci ********** @ oravannahka.helsinki.fi:

Richard< ri **** **********@hotmail.com>潦草地写着以下内容:

在我想到这个问题之前,我已经尝试过这个问题了。这是一件非常简单的事情,但它正在驱使我坚果!是否可以检查int(或任何其他类型)是否没有
值。类似于:



标量类型(如整数)总是有值。因此,你的
问题没有意义。




好​​吧,我应该更加特别。

我有这个:


typdef struct

{

int x;

int y;

}点;


//我现在想制作一个检查Point是否为空的函数


int pointEmpty (点p)

{

返回(p / * isEmpty * /?1:0)

}

我该怎么做?

TIA



>我真的我试着用这个问题来解决这个问题之前我试着打扰你们

。它是如此简单,但它让我疯了!
是否有可能检查int(或任何其他类型)是否没有价值。




int永远不会有没有值。 C不像SQL那样整数

变量可以有null和整数值。 AC变量

可能有一个未初始化或未定义的值,在这种情况下它可能

有任何值,但这与变量无法区分

分配该值。它可能有某种陷阱值b / b值,这是不能测试的,因为如果你尝试程序终止。


指针可能有一个NULL值,这与没有

值不一样。


Gordon L. Burditt


I''ve really tried searching for this before I thought of bother you guys
with this question. It''s such a simple thing, but it''s driving me nuts!
Is it possible to check if an int (or any other type) has no value.
something like:

int i;
...
...
...
if (i==NULL){
......
}

I know this doesn''t work and I know NULL is a pointer. Is there any way
this can be done?
TIA.

解决方案

Richard <ri**************@hotmail.com> scribbled the following:

I''ve really tried searching for this before I thought of bother you guys
with this question. It''s such a simple thing, but it''s driving me nuts!
Is it possible to check if an int (or any other type) has no value.
something like:



Scalar types, such as ints, always have values. Therefore your question
does not make sense.

--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"Parthenogenetic procreation in humans will result in the founding of a new
religion."
- John Nordberg


Joona I Palaste <pa*****@cc.helsinki.fi> wrote in
news:ci**********@oravannahka.helsinki.fi:

Richard <ri**************@hotmail.com> scribbled the following:

I''ve really tried searching for this before I thought of bother you
guys with this question. It''s such a simple thing, but it''s driving
me nuts! Is it possible to check if an int (or any other type) has no
value. something like:



Scalar types, such as ints, always have values. Therefore your
question does not make sense.



Okay, than I should be more spesific.
I''ve got this:

typdef struct
{
int x;
int y;
} Point;

// I now want to make a function that checks if a Point is empty

int pointEmpty(Point p)
{
return (p /*isEmpty*/ ? 1 : 0)
}

How should I do that?
TIA



>I''ve really tried searching for this before I thought of bother you guys

with this question. It''s such a simple thing, but it''s driving me nuts!
Is it possible to check if an int (or any other type) has no value.



An int never has "no value". C is not like SQL where integer
variables can have null as well as integer values. A C variable
may have an uninitialized or undefined value, in which case it might
have any value, but this is not distinguishable from a variable
that is assigned that value. It might have some kind of trapping
value, which can''t be tested because if you try the program terminates.

Pointers may have a NULL value, which is not the same thing as "no
value".

Gordon L. Burditt


这篇关于如何确定int是否没有值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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