Home > Back-end >  There are bosses can you explain it
There are bosses can you explain it

Time:11-03

#include

Int main (void)
{
Char * string_p="48430";
Printf (" % c \ n ", * string_p + +);
Printf (" % c \ n ", string_p [1]).

return 0;
}
This code output is
4
4
There are big explain is why?

CodePudding user response:


String_p is the name of an array of strings=the address of the first character, so * String_p==4, because behind a + +, so the character array pointer backward-shift, String_p [0]=8, so String_p [1]=4

CodePudding user response:

This is the definition of a pointer used to see as much of a pointer.
Char * string_p="48430";//at this point the first address pointer to the string, which address the address of the first character string value is' 4 'that there * string_p=4
Printf (" % c \ n ", * string_p + +);//* and rear + + priority is the same, but they are a combination of the order is from right to left so executed string_p + + first, string_p pointed to the next is worth address, * string_p values of 4
Printf (" % c \ n ", string_p [1]).//just string_p since increases as string_p directed '8' string_p [1] said after the second character is the four behind the four is eight

CodePudding user response:

 printf (" % c \ n ", * string_p + +); 
Printf (" % c \ n ", string_p [1]).

After first printf because + +, therefore is to seek the value of the expression, namely (* string_p + +), then the increase string_p pointer, pointing at the '8' address,
The second is on the basis of the first, so string_p [0] is' 8 ', string_p [1] is' 4 ',

CodePudding user response:

 A [B] 
* (A + B)
* (B + A)
B [A]
//the above four lines equivalent

"ABC" [1]
* (" ABC "+ 1)
* (1 + "ABC")
1 (" ABC ")
//the above four lines equivalent

A [0]
* (A)
[A] 0
//the above three lines of equivalent
  • Related