C expert programming notes (chapter I and chapter II)

Source: Internet
Author: User

1. editor designer Jin Ke Yu law: efficiency (almost) Is everything 2. I have read the ANSIC standard to find fun and benefit. I have not mentioned the specific ANSI C standard. From this, we can see that the char * type can be used as a parameter, but char ** is not acceptable, therefore, when passing multi-dimensional arrays, We need to specify the subscript 3 of the First n-1 dimension. const [cpp] int main (int argc, char * argv []) {// define the const variable of the basic type, where the const position is, the const int x = 2, y = 3; // two constants // define a non-const variable int z = 3; // a common variable // defines a const int * pc = & x; // pointer to a constant // define a constant pointer int * const cp = & z; // constant pointer // define a non-const pointer int * pp = & z; // int pointer pc = & Z; // yes. pc is a pointer to a constant. You cannot use this pointer to modify the value of memory space pointed to by the pointer. However, this pointer can point to another variable // * pc = 10; // No, * the address pointed to by pc is the const variable, and its value cannot be changed. pc is a pointer to a constant, the pointer cannot be used to modify the value of the memory space pointed to by the pointer pc = pp; // Yes, pc is the pointer, and its value can be changed pc is a pointer to a constant, pp is a common pointer. It is acceptable to assign a value to a pointer pointing to a constant using a common pointer. // pp = pc; // It is a pointer pointing to a constant, assign a value to a common pointer. No. If yes, you can use a normal pointer to modify the memory value * cp = x; // yes, you can use a constant pointer to modify the value of the variable pointed to by the pointer. // cp = & x; // No. cp is a constant pointer and the value of the pointer cannot be modified, it is wrong to assign a value to a regular pointer. // pp = & x; // No. pp is a non-const pointer. In principle, it is acceptable to assign a value to it, different compilers have different results // pp = pc; // No, pointer to a constant cannot be assigned to a common pointer pp = cp; // yes, a constant pointer can be assigned to a common pointer const int * const pp = & a; // double const protects both pointer and memory variable return 0;} 4. the ASINC manual re-compiled the related content integer upgrade and normal arithmetic conversion Note: # define TOTAL_ELEMENTS (int) (sizeof (array)/sizeof (array [0]) must be added (Int) forced conversion. Otherwise, the computation result is of the unsigned int type. Unexpected results may occur during the computation with the signed number in the program. error assertions are errors no matter when you encounter malloc (strlen (str), and malloc (strlen (str) + 1) is correct because string processing contains an additional space, used to hold the '\ 0' 6 at the end of the string. A 'l' NUL and two 'l' NULL 7. in the switch, case is not followed by break 97%. In addition, if the word "default" is written incorrectly, the compiler will not detect it. 8. when initializing a string array, if a comma is accidentally missed, the compiler will not send an error message, but will quietly combine the two strings [cpp] # include <stdio. h> # include <string. h> # define TOTAL_ELEMENTS (int) (sizeof (str)/sizeof (str [0]) int main () {char * str [] = {"aaa ", "bbb", "ccc", "ddd" "eee" ,}; printf ("the length of the array is % d \ n", TOTAL_ELEMENTS ); for (int I = 0; I <TOTAL_ELEMENTS; I ++) puts (str [I]); return 1 ;}result: 9. make the first execution of a piece of code different from the subsequent execution time (applying for static variables in the function) 10. I = 1, 2 What is the result of I? The priority of the value assignment operator is higher than the comma, so the actual situation is: (I = 1), 2, so the final value of I is 1 and I = (1, 2 ); the result I is 2; 11. computing order

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.