It shouldn't be initialized. "oranges[3]" is not a valid array index, and cannot be used other than for a comparison against that location.
Quzah.
It shouldn't be initialized. "oranges[3]" is not a valid array index, and cannot be used other than for a comparison against that location.
Quzah.
Hope is the first step on the road to disappointment.
Remember, if you declare an array as
the valid indexes are from 0 to 4, not from 1 to 5.Code:int array[5];
Re-read Salem's post.
Originally Posted by Salem
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.
If initialize oranges with diffrent values like one timeOriginally Posted by quzah
oranges[0] = 999;
oranges[1] = 999;
oranges[2] = 888;
and another
oranges[0] = 999999;
oranges[1] = 999999;
oranges[2] = 999999;
You get diffrent results.
one thing that nobody else picked up on so i'll answer it - there
is a way to get the modulus of a number: there is a function in
stdlib.h called abs () (absolute value) which takes an
integer argument and returns is modulus, or for a more far
reaching version there is fabs () which is defined in math.h
and handles floats. Just so you know.
No No's:
fflush (stdin); gets (); void main ();
Goodies:
Example of fgets (); The FAQ, C/C++ Reference
My Gear:
OS - Windows XP
IDE - MS Visual C++ 2008 Express Edition
ASCII stupid question, get a stupid ANSI
You're not supposed to post in threads older than 2 weeks.
No, *abs() return a positive number. That is, if the number is positive, it is returned unchanged, and if it is negative it is negated. It's the same as this (or the macro below):there
is a way to get the modulus of a number: there is a function in
stdlib.h called abs () (absolute value) which takes an
integer argument and returns is modulus
Modulus doesn't come into it.Code:int sameabs(int x) { return x > 0 ? x : -x; }
Actually, it takes a double and returns a double, but floats work with it too. Or you can write a macro:or for a more far
reaching version there is fabs () which is defined in math.h
and handles floats.
Code:#define ABS(x) ((x) > 0 ? (x) : -(x))
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.