A pointer variable is a variable that contains the memory location of another variable or an array (or anything else in memory). Effectively, it points to another memory location.
For standard variables, you define a type, assign a value to that variable or read the value from it, and you can also read the memory location (&n = memory location of n) of the variable.
For pointers, you can point them to any variable, even another pointer, and you can get the value of the variable it points to (*p), the location of that variable in memory (p), or the address in memory of the pointer itself (&p).
Consider:
long n = 65;
long *p;
p = &n;
Results:
Type | Name | Location | Value
long n 0xA3FF 65
long * p 0x31DF 0xA3FF
So p points to n. Now,
n = 65
&n = 0xA3FF
p = 0xA3FF
*p = 65
&p = 0x31DF
You may find yourself having to use typecasts frequently when using pointers.
Pointers are useful when passing data to functions.
For instance, consider the following function:
void add(int a, int b, int c) { c = a + b; }
The problem here is that the computer copies each variable into a new memory location before passing them to the function as local variables. This function effectively does nothing. However, if you change the function to:
void add(int a, int b, int *c) { c = a + b; }
and call the function by passing in the location of the variable to the function:
add(a,b,&c);
then you can modify the variable itself.
Pointers are also good for working with arrays:
char *c = "Hello World";
int i=0;
while (c[i] != 0x00) { cout << c[i]; c++ } //print one letter at a time.
Answergenerally we use simple pointer, void pointer,null pointer, structure pointer. Answerzero or more (unlimited).
Yes, two different pointer variables may point to the same memory location. Two issues, though... If your code thinks the two pointers represent two different allocations of memory, then you risk deallocating one and not realizing that the other is now invalid. You need to make sure that your compiler optimization settings for volatility are correct, otherwise the compiler could generate code that does not always work correctly.
... are usable. void pointer (generic pointer) : a special type of pointer which point to some data of no specific types. void *p; null pointer : a special type of pointer which point nowhere. it is usually used to check if a pointer is pointing to a null or free the pointer during deallocation of memory in dynamic memory allocation; it is define by using the predefine constant NULL int *p=NULL; wild pointer : uninitialized pointer. it hold a garbage value. i.e it is not pointing to any memory location yet. dangling pointer: pointer pointing to a destroyed variable. it usually happen during dynamic memory allocation when the object is destroyed but not free and the pointer is still pointing to the destroy object.
At any given point of time you cann't get the address of a variables of java program. This is meant for security purpose only.
They both mean the same thing; an array is a type of data structure (a linear structure). A pointer variable is just a variable like any other, but one that is used to specifically store a memory address. That memory address may contain a primitive data type, an array or other data structure, an object or a function. The type of the pointer determines how the data being pointed at is to be treated. Pointers must always be initialised before they are accessed, and those that are not specifically pointing at any reference should always be zeroed or nullified with the NULL value. This ensures that any non-NULL pointer is pointing at something valid. Remember that pointer variables are no different to any other variable insofar as they occupy memory of their own, and can therefore point to other pointer variables.
Pointer-variables are variables, so there is no difference.
In JAVA, all variables are reference variables, and there are no pointer variables. Even though the platform may implement them as pointers, they are not available as such. In C, no variables are reference variables. They are a C++ enhancement. In C++ a reference variable is syntactically the same as a pointer variable, except that the use of the indirection operator (*) is implicit. You do declare reference variables slightly differently than pointer variables but, once you do so, they can be treated as non-pointer variables. Reference variables also cannot be redefined once they have been initialized to point to some object. They are const. Structurally, there is no difference between a pointer variable and a reference variable. They are both still pointers. The compiler just makes it easier to treat reference variables and non-pointer variables the same way.
Answergenerally we use simple pointer, void pointer,null pointer, structure pointer. Answerzero or more (unlimited).
pointer r the variables created in RAM which store the address of a another variable
Yes. All string variables are pointers as are other arrays.
You can declare pointer-variables, if that's what you mean. Example: char *sample = "Sample";
Yes, two different pointer variables may point to the same memory location. Two issues, though... If your code thinks the two pointers represent two different allocations of memory, then you risk deallocating one and not realizing that the other is now invalid. You need to make sure that your compiler optimization settings for volatility are correct, otherwise the compiler could generate code that does not always work correctly.
A pointer is a variable used specifically to store a memory address. We say the variable "points to" the memory address because we can dereference the pointer to access the value stored at that address. The pointer's type determines how that dereferenced value will be interpreted. Being a variable, we can change the stored address and thus change which value we point at. This makes it possible for the same variable to refer to different objects in memory, which includes other pointer variables.
... are usable. void pointer (generic pointer) : a special type of pointer which point to some data of no specific types. void *p; null pointer : a special type of pointer which point nowhere. it is usually used to check if a pointer is pointing to a null or free the pointer during deallocation of memory in dynamic memory allocation; it is define by using the predefine constant NULL int *p=NULL; wild pointer : uninitialized pointer. it hold a garbage value. i.e it is not pointing to any memory location yet. dangling pointer: pointer pointing to a destroyed variable. it usually happen during dynamic memory allocation when the object is destroyed but not free and the pointer is still pointing to the destroy object.
Pointer in C is Memory Reference. It stores memory address of any variable, constant, function or something you later use in your programming. Pointer basically used to ease the referencing of variables and others or in polymorphism and inheritance.
At any given point of time you cann't get the address of a variables of java program. This is meant for security purpose only.
They both mean the same thing; an array is a type of data structure (a linear structure). A pointer variable is just a variable like any other, but one that is used to specifically store a memory address. That memory address may contain a primitive data type, an array or other data structure, an object or a function. The type of the pointer determines how the data being pointed at is to be treated. Pointers must always be initialised before they are accessed, and those that are not specifically pointing at any reference should always be zeroed or nullified with the NULL value. This ensures that any non-NULL pointer is pointing at something valid. Remember that pointer variables are no different to any other variable insofar as they occupy memory of their own, and can therefore point to other pointer variables.