Questions tagged [address-operator]

The name of the prefix unary ampersand operator (&) used in C and C++ to get the address of its operand, i.e. a pointer value pointing to that operand. For example, if `a` is an object of some type `T`, then `&a` will be a pointer value of type `T*` pointing to `a`.

48 questions
29
votes
1 answer

Specific use case of to_address

So apparently C++20 is getting std::to_address. From the cppreference page its use case doesn't seem clear to me. We already have operator& and std::addressof, why do we need yet another function that gives us an address to its argument?
Hatted Rooster
  • 35,759
  • 6
  • 62
  • 122
24
votes
4 answers

Why would anyone want to overload the & (address-of) operator?

Possible Duplicate: What legitimate reasons exist to overload the unary operator& ? I just read this question, and I can't help but wonder: Why would anyone possibly want to overload the & ("address-of") operator? SomeClass* operator&() const { …
Tony the Pony
  • 40,327
  • 71
  • 187
  • 281
15
votes
4 answers

Whats the difference between Reference and Pointer return types in C++

If I were to create a simple object in C++, what is the difference between returning an address of the member vs. returning a pointer. As far as I'm aware, C++ doesn't have automatic garbage collection so it wouldn't be keeping a reference count. So…
wfoster
  • 781
  • 10
  • 23
7
votes
2 answers

How fix AddressOf requires a relaxed conversation to the delegate error

Sorry, this is a mix of C# and VB.Net I have a C# class with with 2 delegates: public delegate string GetSettingDelegate(string key); public event GetSettingDelegate GetSettingEvent; public delegate void SetSettingDelegate(string key, string…
Steve Chadbourne
  • 6,873
  • 3
  • 54
  • 82
7
votes
4 answers

Understanding pointers with a swap program in C

I am trying to better understand pointers and referencing in C, and my course provided the following program as an example. #include void swap(int* a, int* b); int main(void) { int x = 1; int y = 2; swap(&x, &y); …
Caleb Jay
  • 2,159
  • 3
  • 32
  • 66
7
votes
4 answers

Get the address of an Objective-c property (which is a C struct)

I have an Objective-C class which contains a C-style struct. I need to call a C function passing a pointer to this object member (a.k.a. property). For the life of me, I can't figure out how to get the address of this C struct. Using the…
jDawg
6
votes
4 answers

AddressOf alternative in C#

Could anyboby help me with the alternative solution in C# regarding AddressOf operator in VB6? AddressOf returns a long value. What way can I get the output in C#?
Wasif Osman
6
votes
4 answers

" addressof " VB6 to VB.NET

I´m having some problem to convert my VB6 project to VB.NET I don't understand how this "AddressOf" function should be in VB.NET My VB6 code: Declare Function MP4_ClientStart Lib "hikclient.dll" _ (pClientinfo As CLIENT_VIDEOINFO, ByVal abab As…
johan
  • 61
  • 1
  • 2
6
votes
10 answers

Can an address be assigned to a variable in C?

Is it possible to assign a variable the address you want, in the memory? I tried to do so but I am getting an error as "Lvalue required as left operand of assignment". int main() { int i = 10; &i = 7200; printf("i=%d address=%u", i,…
poorvank
  • 7,524
  • 19
  • 60
  • 102
4
votes
6 answers

In C (also C++), how '&' operator works as both address operator and bitwise operator ? As operator overloading is not supported by C

The operator '&' can be used in both of following way int a; scanf("%d",&a); and printf("%d",1&2). But different behaviour (for first as address operator and second time as bit-wise operator). I know operator overloading is not there in C. Then how…
4
votes
2 answers

Declaring int array and changing its elements in C inside a for loop

I am new to C and currently learning arrays. I have this code: #include int main() { int available[6]; for(int o=1; o<=3; o++){ available[o]=20; printf("%d\n",&available[o]); } return 0; } Which is…
user13539846
  • 425
  • 2
  • 5
  • 13
4
votes
1 answer

Why can function pointers be used with or without the address of operator?

In the book, "Beginning C from Novice to Professional", the author does not use the address of operator when assigning a function to a function pointer. I typed in the code on my compiler both with and without the address of operator and it compiled…
Jinzu
  • 1,325
  • 2
  • 10
  • 22
3
votes
1 answer

Passing static method as argument, no address-of operator required?

class ThreadWorker { public: ThreadWorker(void); virtual ~ThreadWorker(void); static void DoSomething(); }; int main() { boost::thread thread1(ThreadWorker::DoSomething); boost::thread thread2(ThreadWorker::DoSomething); …
User
  • 62,498
  • 72
  • 186
  • 247
3
votes
3 answers

pointer argument receiving address in c++?

int y=5; int *yPtr = nullptr; yPtr = &y; I understand that the pointer stores the address of y. and calling *yPtr dereferences y. If I have a call to the void function: int main() { int number = 5; function( &number ); } void function( int…
user3348712
  • 161
  • 10
2
votes
1 answer

Assigning a procedure to dynamically created object

I want to dynamically create TImage controls and then drag and drop them. But if I want to assign the procedure used for the dragging to an event of this Image, it gives me: Error: Wrong number of parameters specified for call to "ClickEvent" This…
1
2 3 4