+ 2

Please help me with this problem in c++, please explain how the code works, thank you.

int main() { string hora = "11:00 PM"; hora[0]++; hora[1] = hora[1] + 2; for(int i=0; i<5;i++){ cout << hora[i]; }

25th Feb 2022, 8:05 AM
DevAbdul
DevAbdul - avatar
1 Resposta
+ 3
<hora> = "11:00 PM" hora[ 0 ] = '1' hora[ 0 ]++ means increment the character value by one, effectively changing its value from '1' to '2' hora[ 1 ] = '1' hora[ 1 ] = hora[ 1 ] + 2 means increment the character value by 2, effectively changing its value from '1' to '3' The for...loop outputs 5 characters of the string <hora>, from index 0 up to index 4.
25th Feb 2022, 8:19 AM
Ipang