|
-
Jun 21st, 2007, 10:55 PM
#1
Thread Starter
Frenzied Member
[RESOLVED] pointer newbie question
Hello, I am new to C#, and I came across a tutorial about pointer:
int *x ;
Declares a pointer variable x, which can hold the address of an int type. The reference operator (&) can be used to get the memory address of a variable.
int x = 100;
The &x gives the memory address of the variable x, which we can assign to a pointer variable
I don't understand what that "address of" mean?
-
Jun 21st, 2007, 11:43 PM
#2
Re: pointer newbie question
The address of an object is the location in memory at which it resides. Each byte in memory has a numerical address the address of an object is the address of the first byte in memory it occupies. A pointer is a variable that contains the memory address of an object. If you have a non-pointer variable you can use the "&" operator to its address, which can then be assigned to a pointer variable.
If you're new to C# then I don't think you need be worrying about unsafe code and pointers just yet, unless you are already a relatively advanced programmer. The .NET Framework is constructed in such a way that you don't need pointers in the vast majority of situations. There are some situations where using pointers can dramatically speed up computationally-intensive sections of code, but for the most part they are unnecessary.
-
Jun 22nd, 2007, 07:51 AM
#3
Hyperactive Member
Re: pointer newbie question
just to expand on that - think of a method that you create. You pass it a value... let's say x, normally you are passing by value, meaning that you pass a copy of the variable x into your method, when you do whatever computation if you don't return that value when the execution is complete then the value of x isn't changed. however if you where to pass by reference it is like saying "there is a variable stored at this memory location" if you then "follow the pointer" and do some computation then the value of x is changed in that case.
as was said before - C# doesn't really need pointers for most of what the world is doing with it. I avoid them, that is probably good advice.
-
Jun 25th, 2007, 03:18 PM
#4
Re: [RESOLVED] pointer newbie question
Pointers can make it much easier to use the API and also interface with binaries created in other programming languages (C/C++, ASM, Delphi...).
I don't live here any more.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|