cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
General C++ Programming
Int Array (Basic)
Int Array (Basic)
Oct 29, 2015 at 3:44am UTC
Dkob1
(227)
Define an int array variable named arx with 3 slots, and stuff a 7 in the last slot
int arx[2]=7;
Is this correct?
Last edited on
Oct 29, 2015 at 3:48am UTC
Oct 29, 2015 at 4:09am UTC
whitenite1
(1785)
@Dkob1
int arx[2]=7;
Is this correct?
Sorry, but no. Remember, arrays start with zero and end one number below the one you're using.
So, you have only, arx[0] and arx[1]. Two slots. You need to declare it as
1
2
3
int
arx[3];
// Then you can use
arx[2] = 7;
Oct 29, 2015 at 4:15am UTC
Dkob1
(227)
Oh I was thinking three slots would be 0, 1, 2.
Ok Thanks.
Oct 29, 2015 at 4:20am UTC
alex067
(401)
Did you define this variable as:
int arx[3]; initially?
That means that if you want to access the last index of this array, it would be [2]
Topic archived. No new replies allowed.