C expert programming note 2

Source: Internet
Author: User
Chapter 2 This is not a bug, but a Language Feature

At any time, if such a statement malloc (strlen (STR); is met, it can almost be determined that it is incorrect, malloc (strlen (STR) + 1 ); yes;

Summary-progress is the computer software engineering andProgramming LanguageAn important motivation for the gradual development of design art;

# Include <stdio. h> int main (INT argc, char ** argv) {const int one = 1; int I = 1; Switch (I) {Case One: printf ("1 ");}}

AboveCodeConst does not actually represent constants;

The break statement actually jumps out of the latest loop or switch statement;

When the operand of sizeof is a type name, parentheses must be added on both sides (which is often mistaken for a function), but parentheses are not required for the operand if it is a variable;

Some experts suggest note that two priorities in the C language are enough: multiplication and division are greater than addition and subtraction, and brackets are added when designing other operators;

Operator combination: it is the arbitration. When several operators have the same priority, it determines which one to execute first;

All the value assignment operators (including those conforming to the value assignment) have the right combination. (They are also combined with the single object operator );

# Include <stdio. h> # include <string. h> char * F () {char Buf [10]; strcpy (BUF, "abcdefg"); Return Buf;} int main (INT argc, char ** argv) {printf ("% s", F ());}

The above Code cannot print the expected value, because the Buf is a local variable. At the end of the function, no one knows what the address pointed to by this pointer is because the variable has been destroyed;

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.