Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++: &a[2] - &a[1] ==?

a is array of integers, if I try to subtract the address value of &a[2] - &a[1] == ? what should the result be 4 or 1 ?

EDIT: see 4th comment on top answer here why he says 1 ?? this is why I'm confused I thought it will be 4

EDIT: here is a test

like image 217
disioe Avatar asked May 24 '11 05:05

disioe


1 Answers

&a[2] is same as &(*(a + 2)) (i.e (a + 2)) and &a[1] is same as &(*(a + 1)) (i.e. (a + 1)). So answer will be 1.

like image 57
Mihran Hovsepyan Avatar answered Sep 20 '22 19:09

Mihran Hovsepyan