+ 5
whats the answer and how does it work?
Char *p="sololearn" ; cout<<p+1;
16 Réponses
+ 9
̶Y̶o̶u̶r̶ ̶c̶h̶a̶r̶a̶c̶t̶e̶r̶ ̶t̶y̶p̶e̶ ̶p̶o̶i̶n̶t̶e̶r̶ ̶i̶n̶i̶t̶i̶a̶l̶l̶y̶ ̶p̶o̶i̶n̶t̶s̶ ̶t̶o̶ ̶t̶h̶e̶ ̶f̶i̶r̶s̶t̶ ̶c̶h̶a̶r̶a̶c̶t̶e̶r̶ ̶i̶n̶ ̶t̶h̶e̶ ̶s̶t̶r̶i̶n̶g̶.̶ ̶T̶h̶e̶n̶ ̶y̶o̶u̶ ̶i̶n̶c̶r̶e̶m̶e̶n̶t̶ ̶i̶t̶ ̶b̶y̶ ̶o̶n̶e̶,̶ ̶s̶o̶ ̶t̶h̶e̶ ̶o̶u̶t̶p̶u̶t̶ ̶w̶i̶l̶l̶ ̶b̶e̶ ̶'̶o̶'̶.̶
+ 7
Shouldn't it be cout<<*(p+1);?
+ 7
If you type cout<<p it will print the whole word, and if you add 1, like p+1 the word will start from the second letter (o) in this case
+ 7
Write it like this *(p+n--)
And the explanation for your case is that it takes the ASCII value of 's' because thats *p and adds 2 on it, so the output is 117
+ 7
No problem
+ 6
@Filip halp me on this one =^=
+ 6
Ohhh, with the explanation?
+ 6
Yes, *p prints just one character, and p prints the whole word, because you wrote it like
char *p="sololearn";
+ 6
I've explained it all in code, so if you want check it out. It's related to your questions:
https://code.sololearn.com/cz9JBW1SOgvB/?ref=app
+ 3
but when it's cout<<*(p+1) it's just o ??
+ 3
thank you
+ 2
but the output is ololearn according to compiler
+ 2
no just cout <<p+1
+ 2
yes please I don't how it works
+ 2
last question I initialize a variable INT n=2;
cout<<*p+n--;
output is 117 ??
+ 1
wow I understood completely