A pointer in c is used to store the address of any variable. it directly points to the memory location.
By using a pointer, we can work faster on memory than a variable.
(i) it reserves space of integer to hold memory.
(ii) The Memory location is a.
(iii) the value at memory location is 5.
How to declare a pointer in c?
int *p1 /*Pointer to an integer variable*/ double *p2 /*Pointer to a variable of data type double*/ char *p3 /*Pointer to a character variable*/ float *p4 /*Pointer to a float variable*/
Explanation of C Pointer with examples
printf("Address of a=%p\n",&a);
printf("The value of a is=%d\n",a);
/* Integer type Pointer, this can hold the
* address of a integer type variable.
int var = 20;
/* Assigning the address of variable var to the pointer
* a. The a can hold the address of var because var is
* an integer type variable.
printf("Value of variable var is: %d", var);
printf("\nValue of variable var is: %d", *a);
printf("\nAddress of variable var is: %p", &var);
printf("\nAddress of variable var is: %p", a);
printf("\nAddress of pointer p is: %p", &a);
Some More Stuff on Pointer in C
1) Pointer to Pointer– A reminder can point to one more tip (which indicates it can save the address of an additional guideline), such reminders are called double tip OR pointer to a pointer.
2) Passing a pointer to function– Reminders can also be passed as an argument to a feature, utilizing this function a feature can be called by referral as well as a variety that can be passed to a function while calling.
3) Function pointers– A featured reminder is just like an additional reminder, it is utilized for storing the address of a function. Function tips can also be utilized for calling a feature in the C program.