Click here to Skip to main content
15,911,715 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: The output seem confusing please clear my doubt Pin
Chuck O'Toole21-Oct-09 5:20
Chuck O'Toole21-Oct-09 5:20 
GeneralRe: The output seem confusing please clear my doubt Pin
venkatasu21-Oct-09 5:44
venkatasu21-Oct-09 5:44 
GeneralRe: The output seem confusing please clear my doubt Pin
David Crow21-Oct-09 5:49
David Crow21-Oct-09 5:49 
AnswerRe: The output seem confusing please clear my doubt Pin
David Crow21-Oct-09 4:33
David Crow21-Oct-09 4:33 
GeneralRe: The output seem confusing please clear my doubt Pin
venkatasu21-Oct-09 4:57
venkatasu21-Oct-09 4:57 
AnswerRe: The output seem confusing please clear my doubt Pin
David Crow21-Oct-09 5:00
David Crow21-Oct-09 5:00 
GeneralRe: The output seem confusing please clear my doubt Pin
venkatasu21-Oct-09 5:03
venkatasu21-Oct-09 5:03 
GeneralRe: The output seem confusing please clear my doubt Pin
David Crow21-Oct-09 5:08
David Crow21-Oct-09 5:08 
venkatasu wrote:
But i don't need any code modifications.


On the contrary, you need to increment i later in the loop. The debugger you are using should have showed you this.

When you exceed an array's boundaries, it messes stuff up elsewhere. Consider your code:

int x[5] = { 1, 2, 3, 4, 5 }, 
    y[5] = { 5, 4, 3, 2, 1 },
    result[5] = { 0, 0, 0, 0, 0 };
These are laid out in contiguous memory such that x comes after y comes after result. When you assigned a value to result[5], which is out of bounds, you actually wrote to y[0].

venkatasu wrote:
I want to know how I got -1 in the first row of the output


By incrementing i at the wrong spot.

"Old age is like a bank account. You withdraw later in life what you have deposited along the way." - Unknown

"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons


GeneralRe: The output seem confusing please clear my doubt Pin
venkatasu21-Oct-09 6:10
venkatasu21-Oct-09 6:10 
GeneralRe: The output seem confusing please clear my doubt Pin
Richard MacCutchan21-Oct-09 6:25
mveRichard MacCutchan21-Oct-09 6:25 
GeneralRe: The output seem confusing please clear my doubt Pin
David Crow21-Oct-09 6:32
David Crow21-Oct-09 6:32 
GeneralRe: The output seem confusing please clear my doubt Pin
Tim Craig21-Oct-09 20:02
Tim Craig21-Oct-09 20:02 
GeneralRe: The output seem confusing please clear my doubt Pin
Chuck O'Toole21-Oct-09 5:05
Chuck O'Toole21-Oct-09 5:05 
AnswerRe: The output seem confusing please clear my doubt Pin
transoft21-Oct-09 7:05
transoft21-Oct-09 7:05 
Questionnumbers with boxes Pin
kbury21-Oct-09 3:59
kbury21-Oct-09 3:59 
AnswerRe: numbers with boxes Pin
David Crow21-Oct-09 4:08
David Crow21-Oct-09 4:08 
GeneralRe: numbers with boxes Pin
kbury21-Oct-09 4:22
kbury21-Oct-09 4:22 
QuestionRe: numbers with boxes Pin
David Crow21-Oct-09 4:29
David Crow21-Oct-09 4:29 
AnswerRe: numbers with boxes Pin
kbury21-Oct-09 4:39
kbury21-Oct-09 4:39 
GeneralRe: numbers with boxes Pin
David Crow21-Oct-09 4:46
David Crow21-Oct-09 4:46 
GeneralRe: numbers with boxes Pin
kbury21-Oct-09 4:53
kbury21-Oct-09 4:53 
GeneralRe: numbers with boxes Pin
David Crow21-Oct-09 4:57
David Crow21-Oct-09 4:57 
GeneralRe: numbers with boxes Pin
kbury21-Oct-09 5:40
kbury21-Oct-09 5:40 
GeneralRe: numbers with boxes Pin
David Crow21-Oct-09 5:43
David Crow21-Oct-09 5:43 
GeneralRe: numbers with boxes Pin
kbury21-Oct-09 5:52
kbury21-Oct-09 5:52 

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.