+ 29
[SOLVED] Can Anyone Please Explain The Following C++ Program ??
/* C++ Program using strings */ int main() { char str[]="Test"; int len = strlen(str); for(int i=0;i<len;i++) { cout << str[i] << i[str] << *(str +i) << *(i + str) << endl; } } [ Output of the above program is coming as : TTTT eeee ssss tttt ] Like I am not able to get what is i [str] and that all.
8 ответов
+ 5
i[str] == *(i + str)
So basically you are doing the same as normal str[i].
The difference is you are checking the address of i first
and and making a sum with first posittion of str after.
Its same effect
Like
2+4 = 6
4+2 = 6
You are just operating in reverse order.
+ 16
Okay and can you also explain the working of i[str] ???
+ 16
Ohhh
Thank You Very Much For Your Help 😊
+ 15
Anya Ok but how will the *(str + i) work ??
+ 15
Keshav No 😅
+ 6
str[¡] == *(str + i)
i[str] == *(i + str)
They all have same effect
+ 5
Basically
*(address)
So
*(str + i)
str store first address position of array. And i it's the value to iterate.
So *(str + 2) -> str[2]
* means access the value in follow address.
0
do u happen to be keval moliya?