The printf function of C language is output in the order from right to left. Each data item can be calculated but does not affect each other.

Source: Internet
Author: User

Today, I saw a Bubble Sorting Algorithm on a website. The final output prinf output function is as follows:

printf("%c",a[i],a[i]);

I suddenly remembered where I had read a saying that the C language output was from right to left, but the details were vague. I tried it after I got back from work. The Code is as follows:

#include <stdio.h>int main(){    int b = 4;printf("%d,%d",++b,b++);printf("\n");printf("%d",b);printf("\n");int a[3] = {1,2,3};int i = 0;printf("%d,%d",a[++i],a[++i]);printf("\n");printf("%d",i);printf("\n");    return 0;}

The output result is as follows:

I personally summarized the following:

C language compilers store data in a pressure stack. Therefore, data is read from the top of the stack to the bottom of the stack during output. However, when printf is used for output, data is read from the right to the left, in addition, each item can be operated, but the results of each operation do not affect each other, but for the variable itself, the value of each calculation will change.

The data exchange method in the bubble algorithm is classic, And I will post the algorithm;

#include<stdio.h>#define NUM 10int main(){     int a[NUM] = {35,32,43,55,66,123,33,44,65,76};     int i ,j;     for(i = 0; i < NUM; i++)       for(j = 0; j < NUM-1;j++)          if (a[j] > a[j+1])          {   a[j]^ = a[j+1];   a[j+1]^ = a[j];   a[j]^ = a[j+1];         }    for (i = 0; i < NUM; i++)       printf("%c",a[i],a[i]);      return 0;}

 

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.