You output so many things in your std::cout
but most of them don't matter.
try
std::cout << sizeof(int(5)) << " " << sizeof(int[5]) << "\n";
which will output
4 20
since int(5)
means a single integer initialised with 5. So sizeof
yields the size of an int
.
On the other hand, int[5]
is what you expect: an array of 5 integers, so sizeof
yields 5*sizeof(int)
.
Two more remarks:
- creating good old arrays with
new
definitely is something a beginner should refrain from. If you need dynamically sized indexable storage, use std::vector
. There is no speed panalty.
- refrain from
using namespace std;
simply type the std::
, that makes the code more readable and clearly separates your stuff from library stuff.