DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   C++ (http://www.daniweb.com/forums/forum8.html)
-   -   C++ arrays (http://www.daniweb.com/forums/thread98686.html)

dsuh06 Nov 27th, 2007 9:30 pm
C++ arrays
 
what does the following do?

int array[6] = { 5, 3, 4, 17, 22, 19 };

int* ptr = array[0]
*ptr = -1;
thank you!

Ancient Dragon Nov 27th, 2007 9:38 pm
Re: C++ arrays
 
The first line initializes the values of the array.
The second line is a syntax error. It should be
int* ptr = &array[0];
The last line sets the value of te first array element to -1.

dsuh06 Nov 27th, 2007 10:09 pm
Re: C++ arrays
 
wow thank you!

then in addition, what does

ptr+= 2
and ptr[1] =9

do?

thank you!!

Ancient Dragon Nov 27th, 2007 11:15 pm
Re: C++ arrays
 
>>then in addition, what does
Think about it and post your answer (or guess)

dsuh06 Nov 27th, 2007 11:24 pm
Re: C++ arrays
 
okies..

so this is what i thought:

ptr+= 2
increases the pointer by two.. so the ptr will now point to array[2]

and ptr[1] =9

the value of index 1 is equal to 9..

is this correct?

thank you!

Ancient Dragon Nov 27th, 2007 11:27 pm
Re: C++ arrays
 
yes, but in the original array which element is set to 9?

dsuh06 Nov 28th, 2007 12:29 am
Re: C++ arrays
 
umm.. is it array[1] which is origially 3 set to 9?

Ancient Dragon Nov 28th, 2007 12:42 am
Re: C++ arrays
 
nope -- try again ?


All times are GMT -4. The time now is 4:55 pm.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC