You do not multiply pointers. If you want to multiply the values that they point to you must dereference them, usually with a *
Assigning an initial value to a pointer variable. Example: int *p= NULL;
A pointer is a variable that stores value of address of a variable. Since a pointer itself is a variable, it is allocated a memory location.Pointer to pointer means a pointer which points to the address of a pointer. In other words a pointer to a pointer has the address of the address of a variable.We can have pointers to int, and pointers to char, and pointers to any structures we've defined, and in fact pointers to any type in C, it shouldn't come as too much of a surprise that we can have pointers to other pointers. If we're used to thinking about simple pointers, and to keeping clear in our minds the distinction between the pointer itself and what it points to, we should be able to think about pointers to pointers, too, although we'll now have to distinguish between the pointer, what it points to, and what the pointer that it points to points.
I presume you referring to the C pointer syntax where an asterisk operator may be suffixed to a type or prefixed to a variable. The following may help to clarify: int*p; int* q; int *r; int * s; All four of these declarations are exactly the same (they are all pointer-to-int variables). Note that the physical position of the asterisk operator makes no difference whatsoever, no matter how much whitespace you use (whitespace is essentially ignored both before and after an operator). Because the type is pointer-to-int, it usually makes sense to use the second variant to separate the variable's type from its name. However, this doesn't really work when declaring multiple pointer variables of the same type on the same line using the comma operator. Consider the following: int* p, q, r, s; While it is natural to assume p, q, r and s are all pointer-to-int types, they are not. The first, p, is the only pointer-to-int type, while all the others are just plain int types. If we really want 4 pointer-to-int types, we need to use the following declaration instead: int *p, *q, *r, *s;
Example: int x; -- integer int *px= &x; -- pointer to integer int **ppx= &px; -- pointer to pointer to integer int ***pppx= &ppx; -- pointer to pointer to pointer to integer
Pointer to Pointer is a double pointer, denoted by (**). Pointer stores the address of the variable and pointer to pointer stores the address of a pointer variable and syntax can be given as int **ptr2ptr;
int* pint; // instantiate a pointer to an int. float* pflt; // instantiate a pointer to a float.
Assigning an initial value to a pointer variable. Example: int *p= NULL;
Double (**) is used to denote the double pointer. As we know the pointer stores the address of variable, Double pointer stores the address of any pointer variable. Declaration : int **ptr2Ptr;
Of course. But why? int *p = (int *)"string";
#include<iostream> int main() { int x=42; int* p=&x; // declare and initialise a pointer, assigning the address of x. }
I have no idea what you mean by that... Some examples for pointers of different types: int *intptr; char *charptr; void *generic_ptr; FILE *stdin; int (*funptr)(int, char **);
normal variable stores a value of the given datatype where as the pointer variable stores the address of a variable. for example int n=10; int *p; p=&n; here p is a pointer variable and n is a normal variable.p stores the address of n where as n stores an integer value. *p prints the value of n,p prints the address of n.
A pointer is a variable that stores value of address of a variable. Since a pointer itself is a variable, it is allocated a memory location.Pointer to pointer means a pointer which points to the address of a pointer. In other words a pointer to a pointer has the address of the address of a variable.We can have pointers to int, and pointers to char, and pointers to any structures we've defined, and in fact pointers to any type in C, it shouldn't come as too much of a surprise that we can have pointers to other pointers. If we're used to thinking about simple pointers, and to keeping clear in our minds the distinction between the pointer itself and what it points to, we should be able to think about pointers to pointers, too, although we'll now have to distinguish between the pointer, what it points to, and what the pointer that it points to points.
int a; -- variable definition"int a" -- string literal
int, float: 0 pointer: NULL
I presume you referring to the C pointer syntax where an asterisk operator may be suffixed to a type or prefixed to a variable. The following may help to clarify: int*p; int* q; int *r; int * s; All four of these declarations are exactly the same (they are all pointer-to-int variables). Note that the physical position of the asterisk operator makes no difference whatsoever, no matter how much whitespace you use (whitespace is essentially ignored both before and after an operator). Because the type is pointer-to-int, it usually makes sense to use the second variant to separate the variable's type from its name. However, this doesn't really work when declaring multiple pointer variables of the same type on the same line using the comma operator. Consider the following: int* p, q, r, s; While it is natural to assume p, q, r and s are all pointer-to-int types, they are not. The first, p, is the only pointer-to-int type, while all the others are just plain int types. If we really want 4 pointer-to-int types, we need to use the following declaration instead: int *p, *q, *r, *s;
Example: int x; -- integer int *px= &x; -- pointer to integer int **ppx= &px; -- pointer to pointer to integer int ***pppx= &ppx; -- pointer to pointer to pointer to integer