Home > Back-end >  The C language
The C language

Time:10-04

The first question: in the char variable assignment for 255, but why will display the output of the % d - 1, the following program
Int main ()
{
Char num_max=255;
Printf (" num_max=% d \ n ", num_max);
return 0;
}
Compile run results: num_max=1


The second question: why to % s output will have one more letter
# include & lt; stdio.h>
# include & lt; Stdlib. H>

Int main ()
{
Char STR [5]="apple";
STR: printf (" % s \ n ", STR);
return 0;
}
Compile run results: apple F

CodePudding user response:

The first
Printf (" num_max=% u \ n ", num_max);
The second

Char STR [6]="apple";

CodePudding user response:

The first data overflow, into 1
The second string array is the last '\ 0'
  • Related