谁能解释一下BOOL和Char?
xcode吧
全部回复
仅看楼主
level 2
phw708 楼主
本人新手,这些看不太懂,尤其是BOOL 什么东西=TRue,这个是什么意思,用通俗易懂的解释一下感谢你们!
2012年12月20日 09点12分 1
level 2
BOOL是布尔型变量,仅有YES和NO两种值,可以直接作为条件判断的式子
char是字符型变量
具体请参见各种C语言书籍(Obj-C里BOOL是YES和NO,C和C++里是true和false)
2013年01月03日 06点01分 2
我记得bool只有真假,微软定义的大写的BOOL多个-1为error
2013年06月08日 09点06分
我记得bool只有真假,微软定义的大写的BOOL多个-1为error
2013年06月08日 09点06分
level 12
楼上正解
2013年01月04日 06点01分 3
level 12
举个例子来讲 随机猜数字的例子 代码如下
2013年01月04日 06点01分 4
level 12

#import <Foundation/Foundation.h>
int main(
int argc,
const
char * argv[])
{
@autoreleasepool
{
int randomNumber=
1;
int userGuess =
1;
BOOL continueGussing=
TRUE;
BOOL keepPlaying=
TRUE;
char yesNo=
' ';
while (keepPlaying)
{
randomNumber=(arc4random()%
101);
NSLog(@"
我们来玩个游戏,猜猜随机数字吧
",randomNumber);
while (continueGussing)
{
NSLog(@"
选择一个0
到100
之间的数字,祝你好运
"
);
scanf(
"%i",&userGuess);
fgetc(stdin);
if (userGuess==randomNumber)
{
continueGussing=
FALSE;
NSLog(@"
我擦,猜对了!
");
}
else
if (userGuess>randomNumber)
{
NSLog(@"
高了
");
}
else
{
NSLog(@"
低了
");
}
NSLog(@"
你猜的是
%d",userGuess);
}
NSLog(@"
还敢玩么,憨比?
y or n ");
yesNo=fgetc(stdin);
if(yesNo==
'y'||yesNo==
'Y')
{
keepPlaying=
TRUE;
}
continueGussing=
FALSE;
}
}
return
0;
}
2013年01月04日 06点01分 5
level 12
看不懂的地方提出来,最好手打在xcode上
2013年01月04日 06点01分 6
level 3
布尔变量只有真或者假。而char变量可以当做一个字符。类如?!。,…x y z 1 5 8 9 6之类中一个。
2013年02月03日 10点02分 7
level 3
布尔型变量相似的做类比
java里:Boolean(值为true和false)
c和c++: BOOL(值为true和false)
Objective-c:BOOL(值为yes和no)
都是可以用于用于判断真假的。当判断条件返回0时,值为相应的false或者no,判断条件非零时,返回true或者yes。布尔型变量常用在if语句或者whlie语句中作为判断条件
2013年02月06日 04点02分 8
level 3
char是基本数据类型的一种,是字符。。。就是abcdefg那些,以及一些特殊的字符,_{}+=都可以用char来表示。
2013年02月06日 04点02分 9
level 4
Reference:
ISO/IEC 14882:2011 C++ programming language
snytax:
2.13.2 Character literals
character-literal:
’c-char-sequence’
L’c-char-sequence’
c-char-sequence:
c-char
[lex.ccon]
c-char:
c-char-sequence c-char
any member of the source character set except
the single-quote ’, backslash \, or new-line character
escape-sequence
universal-character-name
//////************************************************////////
2.13.5 Boolean literals
boolean-literal:
false
true
1 The Boolean literals are the keywords false and true.
ues.
Such literals have type bool.
[lex.bool]
They are not lval-ues
-------------------------------------------------------
<BTY,the bool was belongs to simple-type-specifier.>
------------------------------------------------------------
Version TOW:
<c++ primer>
syntax:
在PRIMER中没有具体给出BOOL和CHAR的delarations,只是给出了elements list,
含义
bool 布尔型 false or YES
char 字符型
上面两种类型都是arithmetic type 合称integral type
/********************************************************/
具体参见Standrad paper......
2013年04月12日 13点04分 10
level 9
楼上正解
2013年04月13日 04点04分 11
level 7
OC BOOL类型是布尔 只能有YES 和NO的值 通常作为开关使用
char类型是字符 'a' 'b' 'c' '1' 通常作为保存字符使用
2013年06月06日 15点06分 12
1