C语言学习注意点(一)

1、Integerdivision truncates:  any fractional partis discarded; Since 5 and 9 are ingegers. 5/9 would be truncated to zero.  SO 5.0/9/0 is not truncated because it is theratio of two floating-point values.

 

2、Expressionsconnected by && or || are evaluated left to right. && or || areevaluated left to right  and evalutationstops as soon as the truth or falsehood of result is know

 

3、FunctionParameters are local to itself, and not visible to any other function. We willgenerally use parmeter for a variable named in the parenthesized list in afunction. Parameters can be treated as conveniently initialized localvariables in the called routine. Arguments –Call by value. This means that thecalled function is given the values of its arguments in temporary variablesrather than the originals.

 

Commonpractice is to place definitions of all external variables at the beginning ofthe source file

Collectextern declaration of variables and functions in a separate file.

 

4、Definitionrefers to the place where the variable is created or assigned storage.

Declarationrefers to places where the nature of the variable is stated but no storage isallocated.

 

5、expr1op= expr2 is equivalent to expr1 = (expr1) op (expr2)

exceptthat expr1 is computed only once. Notice the parentheses around expr2: 

x *=y + 1 means x = x * (y + 1)

 

6、theorder in which function arguments are evaluated is not specified, so the

statement  printf("%d %d\n", ++n, power(2,n));   /* WRONG */

canproduce different results with different compilers, depending on whether n isincremented

beforepower is called. The solution, of course, is to write 

 ++n;   

printf("%d%d\n", n, power(2, n));

 

7、Forexternal and static variables, the initializer must be a constant expression;the

initializationis done once, conceptionally before the program begins execution. For automatic

andregister variables, the initializer is not restricted to being a constant: itmay be any

expressioninvolving previously defined values, even function calls

 

8、Thereis one difference between an array name and a pointer that must be kept inmind. A

pointeris a variable, so  pa=a and  pa++ are legal. But an array name is not avariable;

constructionslike a=pa and a++ are illegal

 

7、Thevalid pointer operations are assignment of pointers of the same type, adding or

subtractinga pointer and an integer, subtracting or comparing two pointers to members ofthe

samearray, and assigning or comparing to zero. All other pointer arithmetic isillegal.

 

 

8、charamessage[] = "now is the time"; /* an array */

char *pmessage = "now isthe time"; /* a pointer */

amessageis an array, just big enough to hold the sequence of characters and  '\0' that

initializesit. Individual characters within the array may be changed but amessage willalways

referto the same storage. On the other hand, pmessage is a pointer, initialized topoint to a

stringconstant; the pointer may subsequently be modified to point elsewhere, but theresult is

undefinedif you try to modify the string contents.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值