Dark Horse Programmer--c Language Knowledge section------Beginners easy to ignore knowledge points

Source: Internet
Author: User
Tags variable scope

These two days to review the basic knowledge of the C language before learning, found a lot of important for beginners but it is easy to ignore the problem, in this summary, and June mutual encouragement.

1, the program if using the header file stdio.h content, even if not write #include <stdio.h> program can be normal operation, will only warn, will not error. This is because the linking program automatically links library functions. So if you use a non-Library function header file, you must write the header file, or the program will be error.

2, when using the scanf function input parameters, if separated by a space, such as:

int A, b;scanf ("%d%d", &a, &b);

When entering parameters, you can use not only spaces as separators, but also the actual Input tab and carriage return as delimiters.

3, in the program we often use the self-added operator (such as: a++), but if someone asked you 10++ the wording, right? A lot of people are not sure. Actually the 10++ is wrong, because a++ is equivalent to a=a+1, so 10++ should be equivalent to 10=10+1, which is obviously wrong.

4. In switch, we often write this:

 int  a = 0  ;  int   b;  switch   (a) { case  0         : B  =1  ;      break  ;  default  : B  =2  ;          break  ; 

But what if it's written like this?

int 0 ; Switch (a) {   case0:        int b=1;          Break ;      default :         int b=2;          Break

In fact, this is wrong, because if a new variable is defined in the case, it must be wrapped with {} or the variable scope is ambiguous. The correct wording should be:

 int  a = 0  ;  switch   (a) { case  0  : { int  b=            ;          break  ;   default  : { int  b=2  ;            break  ; }}   

Oh, that's right. In fact, switch in the default is often ignored, when all cases of the value is not equal to a, you can use the default!

5. It should also be noted that the IF statement as a branching structure must be enclosed in {} when defining a new variable in the IF statement, otherwise it will also report an ambiguous scope error. Such as:

if(>6)    {int a=5;          }

Of course, remember if (10>6) do not add ";" Oh.
6, in the comparison size is, it should be noted that it is best to put the constant value on the left side of the operator, the variable on the right. such as: if (2 = = a), note that the C language is medium so "= =", if written as "=" is an assignment operation.

7. When using the sizeof () function, note the parameters passed in, such as:

intA =Ten;sizeof(Ten);//correctsizeof Ten;//correctsizeof(a);//correctsizeofA//correctsizeof(int);//correctsizeof int;//Error

Dark Horse Programmer--c Language Knowledge section------Beginners easy to ignore knowledge points

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.