C language attention to detail __c language

Source: Internet
Author: User

C language Easy to forget easy to ignore the knowledge point

There is a phenomenon of local short-circuit in logical operators

1.&& 1&&2 and operation of the same truth is true that there is a false if 1 is false then 2 do not judge

2.| | Or an operation that represents a true true and False is False if 1 | | 2, 1 is true, 2 doesn't judge.

Break is encountered in switch statement don't forget to write break

Note the extra character getchar () for character input, can be used to accept a character in the cache, or you can use Rewind (stdin) to empty the cache

3. Random function Arc4random () to [X, Y] obtains random number arc4random ()% (y-x+1) +x;

4.%s encountered ' "" to stop, the array do not poor students out of bounds

5. Char A[6] = {' A ', ' P ', ' P ', ' l ', ' e ', ' d '}; Remember to add ' yes ' if the string is automatically added ' "', ' char ' a[6] =" Apple ";

6. Strlen calculation of the length of the time encountered ' "and the end of the ' no '

String s[] = "Apple"; The number of elements is 6, but the length is 5, the string is automatically followed by a ' yes ', but the length of the calculation does not include ' the '.

7. Note: All involved in the comparison and assignment of strings cannot use > < or = These operators but rather use strcmp (String 1, string 2); strcpy (String 1, String 2) The functions of these strings, compute the length on the strlen, and in the structure also pay attention to the use of strcpy (Student.name, "Lili");

8.char *p = "ios"; *p = ' A '//This is wrong, point to the constant area address, modify the constant area of the address, which is not allowed, will happen to crash

9. In memory allocation if the length of the string is computed, and memory is allocated according to the length of the string, it is remembered that the length of the string is not prefixed with a ' yes ', so remember to add 1 to the calculation of the function.

10. When assigning values to the string, note that the final ' ' is ' to be added







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.