C语言求助。紧急,十分。。。。
坑爹的外教英文作业,不给我们看中文书。哪位大神帮帮我。这个是老师叫我们做的,我一点都不会,求帮助,谢谢
1. Determine the size, minimum and maximum value following data types. Please specify if your machine is 32 bit or 64 bits in the answer. a) char b) unsigned char c) short d) int e) unsigned int f) unsigned long g) float Hint: Use sizeof() operator,limits.h and float.h header files 2. Write logical expressions that tests whether a given character variable c is a) lower case letter b) upper case letter c) digit d) white space (includes space, tab, new line) 3. Consider int val=0xCAFE; Write expressions using bitwise operators that do the following: a) test if at least three of last four bits (LSB) are on b) reverse the byte order (i.e., produce val=0xFECA) c) rotate four bits (i.e., produce val=0xECAF) 4. Using precedence rules, evaluate the following expressions and determine the value of the variables (without running the code). Also rewrite them using parenthesis to make the order explicit. a) Assume (x=0xFF33,MASK=0xFF00).Expression: c=x & MASK ==0 b) Assume (x=10,y=2,z=2;).Expression: z=y=x++ + ++y ∗2c) Assume (x=10,y=4,z=1;).Expression: y>>= x&0x2 && z 5. Determine if the following statements have any errors. If so, highlight them and explain why a) int 2nd value=10 b) Assume (x=0,y=0,alliszero=1). alliszero =(x=1) && (y=0) c) Assume (x=10,y=3,z=0;). y=++x+y;z=z−−>x d) Assume that we want to test if last four bits of x are on
答案:确定以下数据类型大小,最小和最大值,。请注明:如果你的机器是32位或64位的答案,提示:使用sizeof()操作符,头文件 limits.h和 float.h
Answer: On my 32-bit machine (/usr/include/limits.h,/usr/include/?oat.h), the sizes and limits
are as follows. Results may di?er if you used a 64 bit machine.
Data type size (bytes) min max
data type || size || MIN || MAX
char 1 SCHAR MIN (-128) SCHAR MAX (127)
unsigned char 1 0 UCHAR MAX(255)
short 2 SHRT MIN (-32768) SHRT MAX (32767)
int 4 INT MIN (-2147483648) INT MAX (2147483647)
unsigned int 4 0 UINT MAX(4294967295)
unsigned long 4 0 ULONG MAX(4294967295)
?oat 4 FLT MIN(1.175494e-38) FLT MAX(3.402823e+38)
2。写逻辑表达式测试是否一个给定的字符变量
lower case letter (Answer: c>=’a’&& c<=’z’)
upper case letter (Answer: c>=’A’&& c<=’Z’)
digit (Answer: c>=’0’&& c<=’9’)
3。考虑int val=0xCAFE;写做以下的按位运算符的表达式:
(a) We have to test if last three or four bits are on. The possible values are 0x7,0xB,0xD,0xE,0xF.
To test this, ?rst we extract the last four bits. ( int bits=val&0xF; /?last four bits?/). Next we
test if it is one of the possible patterns. ( bits==0x7 || bits==0xB || (bits>=0xD)).
(b) val = ((0xFF & val) << 8) | (val>>8)
(b) val = (val >> 4) | ((val&0xF)<<12)
4。使用优先规则,计算如下表达式,并确定变量的值(不运行代码)。也可以改写他们用括号标明顺序
(a) The operator precedence is ’==’>’&’>’=’. Thus, the expression is equivalent to c= (x & (MASK==0)).
Therefore x=0xFF33,c=0.
(b) The operator precedence is ’++’>’*’>’+’. Thus, the expression is equivalent to z =(x++) + ((++y)?2).
Therefore x=11,y=3,z=10+3?2=16.
(b) The operator precedence is ’&’>’&&’>’>>=’. Thus, the expression is equivalent to y>>= (x & 0x2) && z.
Therefore x=10,y=2,z=1.
5。确定下面的语句是否有错误。如果是这样,请指出,并解释为什么
(a) Variable names cannot start with a number.
(b) ’=’ operator should be replaced with ’==’. The correct version is alliszero =(x==1) && (y==0);.
(c) There is nothing wrong with the statement. While ??> may look suspicious, the expression
sympli?es to y= (++x)+y; z=(z??)>x.
(c) There is nothing syntatically wrong with the statement. However, what we want is ison=(x&MASK)==MASK.
Based on operator precedence, the current expression simpli?es to ison=x&(MASK==MASK)
上一个:C语言与C语言程序设计有啥不同?
下一个:怎么才能学校C语言?