It'll definitely make it clearer there's something there..
that answer is : <!-- Incorrect -->
Haha i knew it couldn't be that easy. But now i'm pretty stumped i must admit.
output is 2 5
explenation:
2 because *(a+1) is the same a[1](the address of a[0]+the size of 1 int resulting in a[1])
5 because &a+1 is the first address after a and *(ptr-1) is that minus the size of 1 int resulting in the last address of a
basicly a + sizeofa - sizeof1int resulting in the address of the last int in a(which contains 5)
sorry for the crappy explenation hard to do when you're tired)
Originally Posted by Hell_Demon
output is 2 5
explenation:
2 because *(a+1) is the same a[1](the address of a[0]+the size of 1 int resulting in a[1])
5 because &a+1 is the first address after a and *(ptr-1) is that minus the size of 1 int resulting in the last address of a
basicly a + sizeofa - sizeof1int resulting in the address of the last int in a(which contains 5)
sorry for the crappy explenation hard to do when you're tired)
Hmmm <!--i wouldn't have gotten that. That sounds right. I guess cause i didn't know that would happen. I thought it would have been just simple pointer arithmetic. Then again i suppose it was simple pointer arithmetic, if i considered the entire array was one increment. Ok, i understand =D -->
im not yet sure if I am infact right, we'll have to wait for b1ackange1 to answer, also to your signature: learn python, its awsome
<!--
This sample really shows that C++ let's you do a whole lot of stuff other
languages don't let you do by giving you access to memory you're not supposed to screw up
The first item is simple: *(a+1) would be the same as a[1] so that's the number 2;
Now for the second part: Indeed &a is a pointer to the address of an int[5]; so when we add 'one' we're adding 'one' of tne same size being int[5]; so we end up at the theoretically next int[5] item in memory, right behind a[5]; so when we then move one int* back from that we are looking at the last item in a[5] which is the number 5;
If you paste this in your compiler you will see that the address is indeed 5* the size of an int larger than &a.
With any of these it's always handy to write a small test app and pasting the code in so you can follow the program flow.
So you got it again HD! nice work!
-->
Originally Posted by Hell_Demon
im not yet sure if I am infact right, we'll have to wait for b1ackange1 to answer, also to your signature: learn python, its awsome
Haha i was conflicted between python and perl. But either way, how much programming experience do you have hell demon?
Originally Posted by zeco
Haha i was conflicted between python and perl. But either way, how much programming experience do you have hell demon?
hmmm, hard to answer, i guess im getting close to intermediate-advanced
anyway im done for tonight(1:01 now ^^)
i hope to have fun with more of these tomorrow, b1ackange1, thanks for posting these. they are a lot of fun to solve
Originally Posted by Hell_Demon
hmmm, hard to answer, i guess im getting close to intermediate-advanced
anyway im done for tonight(1:01 now ^^)
i hope to have fun with more of these tomorrow, b1ackange1, thanks for posting these. they are a lot of fun to solve
xD i also meant, like how long have you been programming
Originally Posted by zeco
xD i also meant, like how long have you been programming
starting with my 7th year on 5th of october, i got a C++ book with which i started when i turned 10
Originally Posted by Hell_Demon
starting with my 7th year on 5th of october, i got a C++ book with which i started when i turned 10
dat verklaart men achterstand...
is het een goed boek?
gebruik je het nog? NL of EN?
Originally Posted by lalakijilp
dat verklaart men achterstand...
is het een goed boek?
gebruik je het nog? NL of EN?
het boek is inmiddels verouderd ^^ daarin gebruikten ze nog Microsoft Visual C++ 6.0
en het behandelde alleen de basisdingen enzo, de rest heb ik via internet geleerd(onder andere mafiacoders(R.I.P.) en hackproviders.com(niet meer wat het geweest was)
Originally Posted by Hell_Demon
het boek is inmiddels verouderd ^^ daarin gebruikten ze nog Microsoft Visual C++ 6.0
en het behandelde alleen de basisdingen enzo, de rest heb ik via internet geleerd(onder andere mafiacoders(R.I.P.) en hackproviders.com(niet meer wat het geweest was)