Input and output problems of printf functions in C language

Source: Internet
Author: User

This question is a very basic, but I have not known the question, is the classmate asked after only then knew, long knowledge.

It is important to note that the printf function is calculated from right to left and output from left to right.

The distance is as follows:

#include <stdio.h>Main () {    int i=8;    printf%d,%d,%d,%d\n", I,--i,i,i--); }

The output of this program is: 7, 7, 8, 8. The reason is thatwhen i++,i--in the printf () function, thevalue of i is refreshed after the printf () function, so in the printf () function,i++,i-- The value of I is not affected temporarily, and ++i 、--I will have an effect.

Actually here is related to the rules of the operation of printf problem, is to first into the stack and then out of the stack, and then output. Specific as follows.

For the parameters in the printf function, enter the stack in the order of the stack, and then into the stack to the bottom of the stack, after the stack to the top of the stack, after the completion of the calculation, starting from the top of the stack, the stack is the right parameter in the printf function, and then the stack is calculated, then the following elements, The first element in the printf function becomes the last calculated element and then outputs the result of the calculation in the right-to-left order, so the result of the above example is as follows.

Take this record for learning!

Input and output problems of printf functions in C language

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.