5-2-2 printf parameters from right to left

Source: Internet
Author: User

In 5-2-2 C, printf calculates the parameter from right to left.

# Include <stdio. h> int main (INT argc, char ** argv) {int B = 3; int arr [] = {6, 7, 8, 9, 10}; int * PTR = arr; // * (PTR ++) + = 123; // printf ("% d, % d \ n", * PTR, * (++ PTR )); printf ("% d, % d \ n", * PTR, * (PTR ++); Return 0;}/* ----- end of main () ----- */output 7, 6
The sequence of * (PTR ++) Execution: I initially thought that because parentheses are given priority, we should first execute auto-increment in parentheses and then take values.

It can actually be: first take the value of the array element pointed to by PTR, and then add itself. And remove the brackets (* PTR ++). The results are identical.

# Include <stdio. h> int main (INT argc, char ** argv) {int B = 3; int arr [] = {6, 7, 8, 9, 10}; int * PTR = arr; * (PTR ++) + = 123; printf ("% d, % d \ n", * PTR, * (++ PTR )); // printf ("% d, % d \ n", * PTR, * PTR ++); Return 0;}/* ----- end of main () ----- */Output 8
Array arr [] = {, 7, 10} after the program runs }.

5-2-2 printf parameters from right to left

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.