Home > Back-end >  C language character in the variable assignment problem
C language character in the variable assignment problem

Time:09-19

For example: char p='abcd'; Printf (" p=% c ", p)
Why you can print out the p value of d
Again if it is char p='abcde'; Printf (" p=% c ", p)
That could go wrong said p behind the assignment is too big (more than four characters)

CodePudding user response:

Have a great god explain, today suddenly run into this type of problem

CodePudding user response:

1. % c is output character
2. "this symbol is a single character, a, b, c, d, e is one character at a time, but if together, is a string, value should be attached with char * p or char p [5]

CodePudding user response:

This problem is more error, the string should use ", "character in single quotes, double quotes frames string represents the address,

CodePudding user response:

refer to the second floor hu421160052 response:
1. % c is output character
2. 'this symbol is a single character, a, b, c, d, e is one character at a time, but if together, is a string, value should be attached with p or char char * p [5]

Why single quotation marks inside put more characters can be compiled through, and then the last character to character variable p

CodePudding user response:

reference Qin Shuai reply: 3/f
this problem is more error, the string should use ", "character in single quotes, double quotes frame string representing address,

Definition of p is a character variable, is a single quote inside should have only one character at a time, but put more characters can also compile run through, automatically taking the last character to the p

CodePudding user response:

Char is type int type theory, because accept ASCII, char a='ABC', is repeatedly put an int value (97,98,99) is assigned to a, will only warn you, but not grammar mistakes

CodePudding user response:

P is a character variable is not a pointer to string or an array, so the char p='abcd'; This assignment is problematic, 'said is one character at a time, since problem is the assignment operation, the result will be undefined,

CodePudding user response:

I answer the one question, for example in the c language is commonly a byte, char type system will only look at eight, so p is d;
  • Related