Click here to Skip to main content
15,893,989 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: C Basic Pin
_AnsHUMAN_ 5-Jun-13 0:35
_AnsHUMAN_ 5-Jun-13 0:35 
QuestionRe: C Basic Pin
David Crow5-Jun-13 4:01
David Crow5-Jun-13 4:01 
AnswerRe: C Basic Pin
David Crow5-Jun-13 5:48
David Crow5-Jun-13 5:48 
AnswerRe: C Basic Pin
Erudite_Eric5-Jun-13 8:15
Erudite_Eric5-Jun-13 8:15 
GeneralRe: C Basic Pin
CPallini5-Jun-13 9:46
mveCPallini5-Jun-13 9:46 
GeneralRe: C Basic Pin
Richard MacCutchan5-Jun-13 21:22
mveRichard MacCutchan5-Jun-13 21:22 
AnswerRe: C Basic Pin
jschell5-Jun-13 9:25
jschell5-Jun-13 9:25 
AnswerRe: C Basic Pin
hans.sch11-Jul-13 7:31
hans.sch11-Jul-13 7:31 
You can subtract two pointers of the same base type, and the result is the number of elements of the base type that fit between the addresses which the pointers hold. Likewise, you can add an integer value to a pointer, and that will result in the address of a data type instance so and so many steps above the original pointer.

Confusing? - Take your example:
C++
int a[]={5,10,15,20};

Assume a starts at address 0x00040000. This is also the address of a[0]. In C, a is the same as &a[0]. a+1 is &a[1] or 0x00040004, and a+2 is &a[2] or 0x00040008.
&a[2]-2 is &a[0] or 0x00040000.

When x-y==z is true, then x-z==y should also be true; when &a[2]-2==&a[0] is true, then &a[2]-&a[0]==2 should also be true. The C language is nice enough to fulfil this.

To calculate the number of bytes between two memory locations, convert the pointers to BYTE* like this:
C++
(BYTE*)&a[2]-(BYTE*)&a[0]

This would evaluate to 8, as you expected. Assuming, of course, that 'int' is a 32-bit integer type.
QuestionHow can i get date valu from ADSI with c++ code Pin
venkatesh528674-Jun-13 21:42
venkatesh528674-Jun-13 21:42 
AnswerRe: How can i get date valu from ADSI with c++ code Pin
Richard MacCutchan4-Jun-13 21:58
mveRichard MacCutchan4-Jun-13 21:58 
GeneralRe: How can i get date valu from ADSI with c++ code Pin
venkatesh528674-Jun-13 22:04
venkatesh528674-Jun-13 22:04 
GeneralRe: How can i get date valu from ADSI with c++ code Pin
Richard MacCutchan4-Jun-13 23:30
mveRichard MacCutchan4-Jun-13 23:30 
QuestionHow to Get USB attached Devices ' name using setupDi calls ? Pin
002comp4-Jun-13 19:01
002comp4-Jun-13 19:01 
AnswerRe: How to Get USB attached Devices ' name using setupDi calls ? Pin
Jochen Arndt4-Jun-13 21:27
professionalJochen Arndt4-Jun-13 21:27 
GeneralRe: How to Get USB attached Devices ' name using setupDi calls ? Pin
002comp5-Jun-13 0:58
002comp5-Jun-13 0:58 
GeneralRe: How to Get USB attached Devices ' name using setupDi calls ? Pin
Jochen Arndt5-Jun-13 1:16
professionalJochen Arndt5-Jun-13 1:16 
GeneralRe: How to Get USB attached Devices ' name using setupDi calls ? Pin
002comp5-Jun-13 2:15
002comp5-Jun-13 2:15 
GeneralRe: How to Get USB attached Devices ' name using setupDi calls ? Pin
Jochen Arndt5-Jun-13 2:49
professionalJochen Arndt5-Jun-13 2:49 
GeneralRe: How to Get USB attached Devices ' name using setupDi calls ? Pin
002comp5-Jun-13 3:00
002comp5-Jun-13 3:00 
GeneralRe: How to Get USB attached Devices ' name using setupDi calls ? Pin
Jochen Arndt5-Jun-13 3:13
professionalJochen Arndt5-Jun-13 3:13 
GeneralRe: How to Get USB attached Devices ' name using setupDi calls ? Pin
002comp5-Jun-13 18:10
002comp5-Jun-13 18:10 
GeneralRe: How to Get USB attached Devices ' name using setupDi calls ? Pin
002comp5-Jun-13 18:40
002comp5-Jun-13 18:40 
GeneralRe: How to Get USB attached Devices ' name using setupDi calls ? Pin
Jochen Arndt5-Jun-13 21:16
professionalJochen Arndt5-Jun-13 21:16 
AnswerRe: How to Get USB attached Devices ' name using setupDi calls ? Pin
Erudite_Eric5-Jun-13 8:16
Erudite_Eric5-Jun-13 8:16 
QuestionRegular expressions send different result in Visual Studio 2010 and Visual Studio 2008 Pin
BadJerry4-Jun-13 6:19
BadJerry4-Jun-13 6:19 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.