Click here to Skip to main content
16,011,608 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: What's wrong here??? Pointer question Pin
Tomasz Sowinski21-Jun-01 9:12
Tomasz Sowinski21-Jun-01 9:12 
GeneralRe: What's wrong here??? Pointer question Pin
Chris Meech21-Jun-01 9:14
Chris Meech21-Jun-01 9:14 
GeneralRe: What's wrong here??? Pointer question Pin
21-Jun-01 9:17
suss21-Jun-01 9:17 
GeneralRe: What's wrong here??? Pointer question Pin
Tomasz Sowinski21-Jun-01 9:35
Tomasz Sowinski21-Jun-01 9:35 
GeneralRe: What's wrong here??? Pointer question Pin
Chris Meech21-Jun-01 10:31
Chris Meech21-Jun-01 10:31 
GeneralRe: What's wrong here??? Pointer question Pin
Chris Meech21-Jun-01 10:33
Chris Meech21-Jun-01 10:33 
GeneralRe: What's wrong here??? Pointer question Pin
markkuk24-Jun-01 21:21
markkuk24-Jun-01 21:21 
GeneralRe: What's wrong here??? Pointer question Pin
21-Jun-01 9:19
suss21-Jun-01 9:19 
The prolbem is that you are allocating enough memory to hold one int item only!!

so your code is accessing invalid memory!
the statement :

*(pPtr+i) = i; //this is going beyond the memory pointed to by pPtr!!

To create a dynamic array, you need to know the number of elements in it and then allocate it:

void MakeArray(int nCount)
{
int * pPtr = new int[nCount];

if (pPtr)
{
for (int i=0; i < nCount; ++i)
{
*(pPtr+i) = i; //This is ok
pPtr[i] = i; //is same as above!
.....
}
//Free the memory
delete [] pPtr;
}
}

Mh2! Smile | :)
GeneralTHANK YOU SOOOOO MUCH!!!! Pin
Richard Cheng21-Jun-01 10:38
Richard Cheng21-Jun-01 10:38 
GeneralRe: What's wrong here??? Pointer question Pin
Rejeesh21-Jun-01 22:41
Rejeesh21-Jun-01 22:41 
Generalcouldnt create empty document message Pin
21-Jun-01 8:01
suss21-Jun-01 8:01 
GeneralLooking for info on wring visitors in C++ Pin
Ben Burnett21-Jun-01 7:30
Ben Burnett21-Jun-01 7:30 
GeneralRe: Looking for info on wring visitors in C++ Pin
Tomasz Sowinski21-Jun-01 7:47
Tomasz Sowinski21-Jun-01 7:47 
GeneralRe: Looking for info on wring visitors in C++ Pin
Ben Burnett21-Jun-01 9:13
Ben Burnett21-Jun-01 9:13 
GeneralSyntax question... Pin
John Uhlenbrock21-Jun-01 6:23
John Uhlenbrock21-Jun-01 6:23 
GeneralRe: Syntax question... Pin
Tim Deveaux21-Jun-01 6:46
Tim Deveaux21-Jun-01 6:46 
GeneralOpening/Editing a simple text file Pin
21-Jun-01 6:15
suss21-Jun-01 6:15 
GeneralRe: Opening/Editing a simple text file Pin
Tomasz Sowinski21-Jun-01 6:31
Tomasz Sowinski21-Jun-01 6:31 
GeneralRe: Opening/Editing a simple text file Pin
21-Jun-01 6:53
suss21-Jun-01 6:53 
GeneralRe: Opening/Editing a simple text file Pin
21-Jun-01 8:05
suss21-Jun-01 8:05 
GeneralRe: Opening/Editing a simple text file Pin
Mark Terrano21-Jun-01 8:46
Mark Terrano21-Jun-01 8:46 
QuestionWhat is the problem here ? Pin
21-Jun-01 5:27
suss21-Jun-01 5:27 
AnswerRe: What is the problem here ? Pin
John Uhlenbrock21-Jun-01 6:41
John Uhlenbrock21-Jun-01 6:41 
AnswerRe: What is the problem here ? Pin
Ben Burnett21-Jun-01 6:53
Ben Burnett21-Jun-01 6:53 
Answeranswer Pin
21-Jun-01 7:57
suss21-Jun-01 7:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.