I am encountering a difference in the serial number of the result. Could not figure it out why it is going like that.
Please explain if you figure out the logic behind the scene.
What do you mean by "the serial number of the result"?
EDIT: I think I see what you are asking. You are wondering why the first version prints 1,2,3,4 (maybe) while the second prints 0,1,2,3. It's because of "undefined behavior". It is (generally) an error to use a variable in the same expression where you are modifying it as you can't be sure whether you will get the old value or the new value. So the first version is wrong.
#include <iostream>
int main ()
{
constchar *bookstr[] = {"Math", "Physics", "Chemistry", "DSP"};
for (int i = 0; i < 4; i++)
std::cout << loop + 1 << "." << bookstr[loop] << "\n";
}
We usually start the loop index at 0 (when reasonable) and limit the loop by a less-than comparison against the size of the array (as opposed to less than or equal to one less than the size of the array).
Also, your char pointers are pointing to string literals, which are constant (you can't modify their chars). Hence the const.