On some fragmentary attention problems

1. Return on value of scanf and printf

1 . Scanf is a function that returns a value, the return value that can be divided into three cases 

     1 ) a positive integer representing the number of the correct input parameters. Such as performing Scanf ( " % D% D " , A &, & B);
      2 ) 0 , indicating the user input does not match, you can not enter any values correctly. Example above, if the user inputs " , 34 " , 0 is returned.
     . 3 ) the EOF, which is a constant defined in stdio.h inside (usually a value of - . 1 ) shows that the input stream has ended. Under Windows, the user presses CTRL + Z, it means the end of the input; use under Linux / Unix CTRL + D 

2 Why scanf format string in front of which,% s and% intermediate space c need it? 
  That's because if not, then a space. . . oldchar input box is a = = . 

3 . By the way, printf return value is the number of characters output, for example, printf ( " 1234 " ) return value is 4, and printf ( " 1234 \ the n- ") Return value is 5.

2. ~ scanf and scanf about the game! = EOF

 

General EOF is - . 1 , the Scanf ( " % D " , & n-)! Scanf = -1 is equivalent to ~ ( " % D", & n-)

 

3. With regard to dynamic array problem

int the n-; 
scanf ( " % d " , & the n-);
 int A [the n-]; // error
 // Note VC ++ 6.0 standard is not allowed to define dynamic arrays, but now seemingly standard are supported, so this it can be ignored

4.long long int type

Long  Long type 0 denotes 0LL

5.unsigned int type

Many STL function returns a value of unsigned, so it is quite common 
to use to pay attention to the type unsigned int 
unsigned int 0 1 becomes positive infinity minus

6. The short circuit characteristics and use precautions

// short-circuit characteristic can not be put in brackets inside ++ if otherwise the second ++ may not take effect 
if (ANS1> && ANS2 In Flag => = In Flag) {
 BREAK ; 
ANS1 ++, ANS2 ++ ; 
}

7.printf () function is a double problem of output

printf () function does not exist in% lf 
printf () Output data is not a double or an error occurs with lf

8.bool type of problem

Try not to 0 and 1 to use as the false and true 
because if not careful Save 0 1 would not be able to become negative as a normal condition is determined to terminate the

9.define problem

// Do not re-define keyword when the definition of the system, when used otherwise error will be back, looking for errors found autistic 
#define max 1000

10. Global variables and arrays

And after the global array variables are defined by default 0

11. The definition of double talk for loop variable

// variables can be defined less and less defined
 // Do not define the same name variables
 // try a little technical content of the definition of variables, not to engage in a pile a, b, i, j to fool people

 

// better not defined as ij, because too difficult to distinguish, ha ha
 // if written i, j must be careful not to use mixed

12.% c input character

1 .
    // can not try not to use% c
    @ even to enter a character, but also the definition of a character array str [], enter% s, str with [0] 
   represents a character
 2 .
    Int n-;
    char A, B ; 
   Scanf ( " % D " , & n-); 
   Scanf ( " % c% c " , & a, & B); // Note c% a space in front oh, so do not swallow the transport

 

Guess you like

Origin www.cnblogs.com/1911087165zzx/p/11344139.html