Hello,
I have some confusion with Initilization of int.
Qt Code:
#include <iostream> using namespace std; int main() { int *p = new int[4]; for( int i = 0; i < 6568; i++ ) { p[i] = i; cout << i << " ->> " << p[i] << endl; } return 0; }To copy to clipboard, switch view to plain text mode
Above, i have initilize int *p = new int[4];
when i run this program on windows it get crashed after printing
why is it so ????Output :
0 ->> 0
.
.
.
.
6567 ->> 6567
And instead of Initilizing like this
int *p = new int[4];
if i initilize
int *p = new int[100];
then on running this example it get crahsed on 182 ?
why is it so ???
can any body explain me why this happens ?Output :
0 ->> 0
.
.
.
.
182 ->> 182
normally we expect that int[100] will take more values int[4], but its completely different here..!!
can any body tell me what does these below initilization says..!!
int *p = new int();
int *p = new int(10);
int *p = new int[10];
Thanks & Best Regards
Kunal Nandi
Bookmarks