Include<stdio.h> #include <iostream>int main () {char a[] = "123"; char b[] = "ABCD"; if (a > B) {printf ("a>b \ n ");} elseprintf ("a<b\n");p rintf ("%p\n%p\n", A, b); system ("Pause");}
Is such a topic, ask you the final output is a>b or a<b, the answer is a>b.
I see, this A and B ratio is what ah, if it is according to strcmp () method to compare, that certainly a<b ah, that obviously is not, then should be compared to the pointer address size, but this thing is not randomly assigned, is not my posture level is not enough? So I started trying.
The first piece of code in the Vs2017debug mode is actually a>b, and the answer to the question is the same.
, but once we change the order of the definitions of A and B,
#include <stdio.h> #include <iostream>int main () {char b[] = "ABCD"; char a[] = "123";//change the position of a/b definition if (a > {printf ("a>b \ n");} elseprintf ("a<b\n");p rintf ("%p\n%p\n", A, b); system ("Pause");}
The answer becomes a<b, is it metaphysics? What is the larger address defined first? Then I can't spray the subject.
Because this is not the case, it is also the original code, and when we replace debug with release, we find that the result is the opposite and becomes a<b.
This problem is not rigorous, in fact, C language to the compiler for memory address allocation order does not have a hard rule, from the compiler's point of view, the variable address can be randomly arranged, and does not affect the use of addressing, not necessarily in order to arrange. Different compilers are assigned in different ways. For example, in the debug mode of VS, the defined address is larger, the address defined is smaller, and the release mode is the opposite. Today is also a rise in posture, learning a.
On the relationship between defining order and memory allocation--a non-rigorous C-language problem