Home > Back-end >  How to use % s output string.
How to use % s output string.

Time:09-29

Typedef struct {
Char ch [MAXLEN];//static array implementation (fixed-length sequential storage)
Int length;
} SString;
SString sub.
Sub. Ch [0]='0';
Sub. Ch [1]='y'
Sub. Ch [2]='e';
Sub. Ch [3]='s'.
Sub. Ch [4]='\ 0';
1. The printf (" % s ", sub. Ch); Output: 0 yes
2. If, no sub. Ch [0] assignment, printf (" % s ", sub. Ch); The output is empty,
3. If, no sub. Ch [4]='\ 0', printf (" % s ", sub. Ch); 0 yes + gibberish, until find 0,
Should be % s output string, starting with a char type variable, ends in '\ 0',

CodePudding user response:

% s is the output string, the output is a character in a character output, until meet '\ 0' stop output, if wrong ch [0] assignment, so what is should seeing ch [0], if it is' \ 0 'nothing so natural output,
If there is no '\ 0' as the ending, so will continue to find back until we find '\ 0', so there will be a cross-border access, the result is undefined,
  • Related