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;}