Results 1 to 3 of 3

Thread: Little confusion Regarding general Initilizaion.. :confused:

  1. #1
    Join Date
    Oct 2007
    Posts
    21
    Thanks
    2
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Little confusion Regarding general Initilizaion.. :confused:

    Hello,

    I have some confusion with Initilization of int.

    Qt Code:
    1. #include <iostream>
    2.  
    3. using namespace std;
    4. int main()
    5. {
    6. int *p = new int[4];
    7. for( int i = 0; i < 6568; i++ )
    8. {
    9. p[i] = i;
    10. cout << i << " ->> " << p[i] << endl;
    11. }
    12. return 0;
    13. }
    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

    Qt Code:
    1. 0 ->> 0
    2. .
    3. .
    4. .
    5. .
    6. 6567 ->> 6567
    To copy to clipboard, switch view to plain text mode 

    why is it so ????


    And instead of Initilizing
    int *p = new int[4];

  2. #2
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Little confusion Regarding general Initilizaion.. :confused:

    you create an array with size == 5 and then in a loop you get index out of range. change index to 6 (i < 6 not 6568) and then try again.

  3. #3
    Join Date
    Oct 2007
    Posts
    21
    Thanks
    2
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Little confusion Regarding general Initilizaion..

    I m deleteing this Thread so please don't reply to this thread...!!
    Please reply to the thread having same subject title.
    this one is incomplete..!!!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.