Problem in understandting Multi dimensional array and nested loops
Expand Post »
hey guys i know its kinda noobish not to understand them since i been coding for 1 month but there rlly some stuff which confuses me in multidimensional array and nested loops like here in this program
I wanted to know if i sum up like in the array for example num[5][10] i wanted to know which get summed first if i did total+=num[x][i]; but here in this program i made i got weird error which i think shouldn't produce it so please someone enlighten me because till now i understand all stuff pointers memory management and hard stuff in C but i don't understand these multi and nested loops
Re: Problem in understandting Multi dimensional array and nested loops
the error is probably due to the fact that 'x' isn't initialized, so it's value is something like negative eleventy thousand, causing your program to crap the bed when it uses it as one of the array indices.
Re: Problem in understandting Multi dimensional array and nested loops
Whats with return getchar() ? You got several other ways to pause the output.Use one of them rather than this because even though you return some random character as the return of main and exit the OS thinks that the process didn't terminate properly because of a non zero return value.Which of course doesn't cause any problem here but would definitely cause great problems in future when you write some important code.
So better correct it now.
Re: Problem in understandting Multi dimensional array and nested loops
yah i know now but what if i wanna count like row by row like
{1,3,4} {3,5,6} it will count 1 + 3 and 3+5 and 6 + 4 ?
should i switch variables x first then i 2nd ?
Whats with return getchar() ? You got several other ways to pause the output.Use one of them rather than this because even though you return some random character as the return of main and exit the OS thinks that the process didn't terminate properly because of a non zero return value.Which of course doesn't cause any problem here but would definitely cause great problems in future when you write some important code.
So better correct it now.
well for getchar() coz sometimes i use dev when testing a program its a habbit of me to put return getchar(); rather than writing small thing since its a program made for learning
well for getchar() coz sometimes i use dev when testing a program its a habbit of me to put return getchar(); rather than writing small thing since its a program made for learning
It's better to return a fixed value when your program has exited successfully because in your current program, the return value depends on what key the user has pressed, not a very good habit IMO.
If you just write it like: return getchar(); , how can you know then whether your program has exited successfully or not?
Last edited by tux4life; Jul 17th, 2009 at 9:53 am.
Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.
This thread is more than three months old
No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.