C语言学习注意点(一)

    xiaoxiao2021-03-25  104

    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.

    转载请注明原文地址: https://ju.6miu.com/read-14012.html

    最新回复(0)