Home > Back-end >  A character array, bosses, please answer
A character array, bosses, please answer

Time:04-30


Figure 1
 # include & lt; stdio.h> 

Int main (void) {
Char ch1 and ch2 and ch3, [20] a={0};
int i;

Printf (" Enter a first and last name: ");
for (; (ch1=getchar ())==' ')
;
for (; (ch2=getchar ())!=' ')
;
For (I=0; (ch3=getchar ())!='\ n'; I++)
A [I]=ch3;
For (I=0; I & lt;=19; I++) {
Putchar (a [I]);
}
Putchar (', ');
Putchar (ch2);
Putchar (ch1);
Putchar ('. ');

return 0;
}


Figure 2

FIG. 3

FIG. 4

I know the correct wording is line 14 instead for (I=0; A [I]!=0; {i++),
1. But why this error code shows the result of (figure 2), the name is "a"? Decimal 0 should be "null character", isn't it?
2. Why written for line 14 (I=0; I & lt;=20; I++) {, code (FIG. 3) the display of the results of one or more "a"?
Why line 14 3. Write for the for (I=0;; {i++), code (figure 4) shows the result, the code of the part still have a lot of "a" in it?

CodePudding user response:

Actually computer after each byte of physical memory has values and is read/write, never because of the so-called new, delete or malloc, free and is created and destroyed, the difference only lies in the operating system memory management module can find when you read and write and whether to take appropriate action, and the granularity of the operating system manages memory rather than bytes page, a page is usually 4 KB,

CodePudding user response:

Because the piece of memory of the original value of the byte 0 x61