Short-circuit operations and format characters

Source: Internet
Author: User
Tags format message

The 0,1 law in logical operation

0 && A ===> 0

1 && a ==> a

0 | | A = a

1 | | A ===> 1

By the above know any number with 1 phase or both is 1

Any number with 0 and both is 0.

Short-circuit operations occur only in logical expressions;

In or operations, when the first expression is true (not 0), or the second expression of the operation does not operate, the whole is the value of the first expression

At the time of the operation, when the first expression value is False, then the second expression of the operation is not evaluated, and the whole is the value of the first expression.

The computer treats the expressions on either side of the logical operator as conditional expressions;

C Language for the bar table in the process of the lag self-increment operation is: first with no self-increment before the conditions of judgment, and then immediately self-increment;

int i = 0;

int j = 2;

int k;

K = i++ && ++j;

The resulting i,j,k values are 1,2,0, respectively.

When is the problem true?

For C compiler software, the implementation of the "discipline, lenient towards others" guidelines, that is, the input time is not 0 true, the output of the time 1 bit true

About output and input functions:

    1. The input and output is implemented by invoking the C system function.

    2. Input: scanf () output: printf ()

    3. The format character is the input and output function, let c decide the value output/in format message

      printf ("%u\n",-1);-1 's complement of 32 1, which is output as unsigned integer decimal, then size is 2^32-1

printf ("%4d,%-2d,%06d", N, N, N);

The above%4d expression output with 4 bit output, if the number of digits more than 4, then retain the original number of digits, if not enough in left fill space

%-2d ........ ................. Right fill space

%06d ... .... ... .... ... .... .... ... .... ..... .... ..... .... ........................... Left fill 0 instead of space

printf ("%5.2f\n", 5.6);//5.2f represents the total number of digits 5 bits, of which the decimal place 2 bits, the integer bit 2 bits, the decimal point 1 bits

One basic principle: no loss of correctness in order to satisfy the output format

The format allows the precise, precise location to be located accurately and accurately so that it is positioned correctly;

2. Input function

scanf ();


int n;


scanf ("%d", &n);

The contents of "" in the scanf () function will never be printed to the screen; in fact, it is the format required for the user to enter data again.

We don't want to add anything other than format characters when we're programming.

Short-circuit operations and format characters

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.