+ 2

could someone explain this?

// why a = 0x28ff10 ? // what is *(a + 2) doing ? #include <iostream> using namespace std; int main() { int a[4] = {1,2,3,4}; cout << a << endl << *(a + 2) << endl << 0x28ff10; }

24th Jul 2016, 10:53 AM
Jetset Willy
Jetset Willy - avatar
4 Answers
+ 2
cout<<a; is giving you location of a[0] and cout <<*(a+2); is giving you value at a[2]
24th Jul 2016, 11:31 AM
chaitanya guruprasad
chaitanya guruprasad - avatar
+ 1
0x28ff10 is a hexadecimal number literal (can be recognized by the leading "0x" that just states that the following literal is hexadecimal, i.e. to the base of 16).
24th Jul 2016, 12:29 PM
Stefan
Stefan - avatar
0
Thanks to both
25th Jul 2016, 7:21 PM
Jetset Willy
Jetset Willy - avatar
0
How is (a + 2) possible? It sounds like it's trying to add the literal 2 to an array of integers which should spit out a compilation error.
27th Jul 2016, 6:33 AM
Michael Col
Michael Col - avatar