Hello everyone. I have a declaration that starts off like this

inta data[100];
size_t i;

I have to write a C++ segment code that will shift data[50] and data[98] up one spot to the locations data[51] and data[99]

Then I am supposed to insert the number 42 in data[50]

Any ideas on How I can do this?

Two thoughts on this one.

A. Use memmove (which allows source/destination overlap) to relocate the values like so:


B. Use a for loop that works backwards.

for(int i=99;i>50;i--){data[i]=data[i-1];}

Frankly, the second should have been a little obvious.