A pointer is a variable whose value is the address of another variable, i.e., direct address of the memory location. Like any variable or constant, you must declare a pointer before using it to store any variable address.
The general form of a pointer variable declaration is −
type *var-name;
Here, type is the pointer’s base type; it must be a valid C data type and var-name is the name of the pointer variable.
The asterisk * used to declare a pointer is the same asterisk used for multiplication. However, in this statement the asterisk is being used to designate a variable as a pointer.
The unary or monadic operator & gives the “address of a variable’”.
The indirection or dereference operator * gives the “contents of an object pointed to by a pointer”.
Below is the source code for C program to perform Array of pointers which is successfully compiled and run on Windows System to produce desired output as shown below :
SOURCE CODE : :
/* C program to perform Array of pointers */
#include <stdio.h>
int main()
{
/*declare same type of variables*/
int a,b,c;
/*we can create an integer pointer array to
store the address of these integer variables*/
int *ptr[3];
/*assign the address of all integer variables to ptr*/
ptr[0]= &a;
ptr[1]= &b;
ptr[2]= &c;
/*assign the values to a,b,c*/
a=100;
b=200;
c=300;
/*print values using pointer variable*/
printf("\tValue of \ta: %d \tb: %d \tc: %d\n",*ptr[0],*ptr[1],*ptr[2]);
/*add 10 to all values using pointer*/
*ptr[0] +=10;
*ptr[1] +=10;
*ptr[2] +=10;
printf("\n\tAfter adding 10\n\n");
printf("\tValue of \ta: %d \tb: %d \tc: %d\n",*ptr[0],*ptr[1],*ptr[2]);
return 0;
}
Output : :
/* C program to perform Array of pointers */
Value of a: 100 b: 200 c: 300
After adding 10
Value of a: 110 b: 210 c: 310
Process returned 0
Above is the source code for C program to perform Array of pointers which is successfully compiled and run on Windows System.The Output of the program is shown above .
A pointer is a variable whose value is the address of another variable, i.e., direct address of the memory location. Like any variable or constant, you must declare a pointer before using it to store any variable address.
The general form of a pointer variable declaration is −
Here, type is the pointer’s base type; it must be a valid C data type and var-name is the name of the pointer variable.
The asterisk * used to declare a pointer is the same asterisk used for multiplication. However, in this statement the asterisk is being used to designate a variable as a pointer.
The unary or monadic operator & gives the “address of a variable’”.
The indirection or dereference operator * gives the “contents of an object pointed to by a pointer”.
Below is the source code for C program to perform Array of pointers which is successfully compiled and run on Windows System to produce desired output as shown below :
SOURCE CODE : :
Output : :
Above is the source code for C program to perform Array of pointers which is successfully compiled and run on Windows System.The Output of the program is shown above .
need an explanation for this answer? contact us directly to get an explanation for this answer