+ 1

why output llo? could explain? #include <iostream> using namespace std; int main() { char *pString="hello"; pString+=2; cout<<pString; }

23rd Aug 2016, 10:48 AM
Lekhraj Singh
Lekhraj Singh - avatar
2 Respuestas
+ 1
Because pstring has first base add of hello i.e add of h and then it is incremented by 2 so pstring has now address of l and so it pints llo
23rd Aug 2016, 12:04 PM
Trt
+ 1
the char type stores the whole word and return the index requested in the cout. in that case it request for the third character and thats the first "L" it printa the rest as the pointer stores the whole word at once, hope that helps.
26th Aug 2016, 2:15 PM
Igor Busquets
Igor Busquets - avatar