In a program I am writing I am experiencing unexpected output when printing data from an array. I have tried with float and double. Here is the code:
#include <iostream>
int main()
{
double vector[3]{ 193.09375 , 338.5411682 , -4.0 };
double pVecX{ 193.09375 };
double pVecY{ 338.5411682 };
double pVecZ{ -4 };
std::cout << std::dec << vector[1] << '\n' << vector[2] << '\n' << vector[3] << '\n' << '\n';
std::cout << std::dec << pVecX << '\n' << pVecY << '\n' << pVecZ << '\n';
system("Pause");
return 0;
}
This is the output:
338.541
-4
1.42292e-306
193.094
338.541
-4
Press any key to continue . . .
Issues: I expected the vectors to print in reverse order from how they were entered into the array. (Even though I ask for [1]..[2]..[3], it is printing [2]..[3]..[1] (I Think that is the order))
When part of the array, the number "193.09375" becomes a (seemingly) random notated number, and is different every time the program runs.
I was reading about variables and understand that a variable stored outside of the range it is initialized as can cause wrap-around, I just do not know why that is happening here. (I assume it is based on the negative notation.)
I am certain that I am missing something simple, and I am fairly new.