Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

What is the different between a[i+1] and a[i]++?

I am not able to understand why both values are different and how does it change?

int a[100]

for(int i=0; i<100; i++)
cin >> a[i];

int i=20;

cout << a[i+1] << endl;
cout << a[i]++;

I tried to know value of both

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

a[i+1] that means value of i+1th index. which means, lets suppose if i=20 and it has value of 50 and a[21] has value of 200 then a[i+1] means a[i+1]=200
so when it’s about a[i+1] then it point to the next
and a[i]++ that means increase 1 by ith index value.
so i=20 and a[i]=50 and a[i]++ means 50+1 which is 51

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading