I am confused in AddressOf in c# and pointer in c++ ? Am i right that Addressof is manage execution and pointer is unmanage execution or something else?
What is the difference between AddressOf in c# and pointer in c++
314 Views Asked by Pankaj AtThere are 2 best solutions below
Himanshu
On
The sample from MSDN tells most of the story:
int number;
int* p = &number;
Console.WriteLine("Value pointed to by p: {0}", p->ToString());
This assigns the address of the number variable to the pointer-to-an-int p.
There are some catches to this: 1. The variable whose address you are fetching must be initialized. Not a problem for value types, which default, but it is an issue for reference types.
In .NET, variables can move in memory without you being aware of it. If you need to deal with the address of a variable, you really want to use fixed to pin the variable in RAM.
& can only be applied to a variable, not a constant nor a value. (In other words, you cannot use a construct like int* p = &GetSomeInt();)
Again, your code must be compiled in unsafe mode, which flags the CLR that you will be using features outside the managed code "safety net."
Related Questions in C#
- Passing arguments to main in C using Eclipse
- kernel module does not print packet info
- error C2016 (C requires that a struct or union has at least one member) and structs typedefs
- Drawing with ncurses, sockets and fork
- How to catch delay-import dll errors (missing dll or symbol) in MinGW(-w64)?
- Configured TTL for A record(s) backing CNAME records
- Allocating memory for pointers inside structures in functions
- Finding articulation point of undirected graph by DFS
- C first fgets() is being skipped while the second runs
- C std library don't appear to be linked in object file
- gcc static library compilation
- How to do a case-insensitive string comparison?
- C programming: Create and write 2D array of files as function
- How to read a file then store to array and then print?
- Function timeouts in C and thread
Related Questions in C++
- C++ using std::vector across boundaries
- Linked list without struct
- Connecting Signal QML to C++ (Qt5)
- how to get the reference of struct soap inherited in C++ Proxy/Service class
- Why we can't assign value to pointer
- Conversion of objects in c++
- shared_ptr: "is not a type" error
- C++ template using pointer and non pointer arguments in a QVector
- C++ SFML 2.2 vectors
- Lifetime of temporary objects
- I want to be able to use 4 different variables in a select statement in c ++
- segmentation fault: 11, extracting data in vector
- How to catch delay-import dll errors (missing dll or symbol) in MinGW(-w64)?
- How can I print all the values in this linked list inside a hash table?
- Configured TTL for A record(s) backing CNAME records
Related Questions in POINTERS
- Why we can't assign value to pointer
- C++ template using pointer and non pointer arguments in a QVector
- Allocating memory for pointers inside structures in functions
- OpenLayer 3: Map pointer up event can not be triggered when the map created on overlay
- Suspicious pointer-to-pointer conversion (area too small) in C
- Why is implicit pointer of pointer to pointer conversion legal?
- using memcpy to copy arrays passed as parameters
- Smart pointer vs owning raw pointer
- Program not compiling after casting pointer
- Is it legal to compare dangling pointers?
- 2D array, sort rows by sum
- Malloc confusion
- Trying to receive a vector2f from an object pointer
- How to call a non-class member function with pointers as parameters with QtConcurrent::run?
- Reverse linked list in java
Related Questions in C++-CLI
- How can I specify the ASP.NET probing path for automatic C++/CLI appdomains?
- How to assign (Root)Folder ID in C++? Wherein, those files and folder under it would have the same ID as the RootFolder
- How to initialize a String^ *
- Non-managed referenced code strangely, "magically" changes its state for no reason when wrapped in managed
- VC++/CLI: How to prevent an unmanaged object from being destroyed when it goes out of scope?
- Is FreeHGlobal() required to free unmanaged string passed in a function?
- C++ Generalize delegates
- PInvoke vs CLI wrapper, C++ functionality to C#
- Hide some methods in ref class
- Unable to load dll after it was signed
- Override C++/CLI functions
- AccessViolationException - When calling Botan::LibraryInitializer
- How to correctly do operator overloading in C++/CLI?
- msclr is not being used
- How to - SHA1 hash of plaintext using SHA1CryptoServiceProvider in C++/CLI?
Related Questions in ADDRESS-OPERATOR
- Why can't I use `&&a` in C?
- Reading String of Varied Sizes // String Manipulation C++
- Why does the address operator come as a default member of C++ class and what is it?
- Why does a pointer behave like this in c++
- Passing static method as argument, no address-of operator required?
- apparent discrepancy with sizeof and addressof
- How &(*x) works? Details below
- dynamic database driven menus in VB.Net
- What is the difference between AddressOf in c# and pointer in c++
- Passing a VBA class that implements an ATL interface, to an ATL method
- In C (also C++), how '&' operator works as both address operator and bitwise operator ? As operator overloading is not supported by C
- How to cast and pass the address of a variable to a function in C
- Understanding pointers with a swap program in C
- VB.NET: Pointer and Address Operator from C / Convert C to VB.NET
- VB.NET - AddressOf returns Nothing?
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
AddressOf is a VB operator, and doesn't exist in C#. It creates a delegate to a procedure. The delegate can be used later to call the procedure in code that does not include the procedure's name.
A pointer in C/C++ is a representation of an address in memory. You can create a pointer to a function and use it to call that function, so in that particular case pointers and delegates behave similarly. However, delegates are not simply function pointers. The most important difference is that delegates can be chained, and call more than one procedure at once.