+ 1

String index starting from 1. Why *s value put in starting of string why not putting middle of the string?Plz explain how?

char s[]="fine"; *s='n'; cout<<s;

16th Sep 2020, 12:20 PM
Suparna Podder
Suparna Podder - avatar
2 odpowiedzi
+ 2
*s represent first index means *(s+0) which is n so f will replace to n that's why Output will be nine
16th Sep 2020, 12:31 PM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 2
... Array/string index definitely does not start from 1 in C++. When used as a pointer, s points to the first character in the C style string, which is 'f'. The resulting value of the operation would be "nine'.
16th Sep 2020, 12:33 PM
Fermi
Fermi - avatar