It happens because the
main
function came to an end without any error being detected: zero is a return code indicating "normal exit".
Why did it exit sooner than you expected? Because NULL is defined as 0. And because "=" is an asignment. And because 0 is "false" as far as C++ is concerned.
So when your code does this:
int num=0;
while ( num = NULL )
{
...
}
It's the equivalent of saying:
int num=0;
while ( false )
{
...
}
I suspect you need to do this:
int num=0;
int i=0;
while ( num == 0 )
{
cout<<"please enter element "<<i<<" ::: ";
cin>>num;
arr[i]=num;
i++;
}
But that won't work for long either, as you haven't allocates any "real" space to your array!