Pointers are one of the most important feature in C language. Some features like dynamic memory allocation cannot be done without pointers.
We know that all variables have an address which can be accessed using "&" sign. For an example loot at the code given below. Try to run it.
#include <stdio.h>
int main () {
int number;
printf("Address of variable 'number' = %x\n", &number );
return 0;
}
This will print the address of the number variable.
So what's the relationship with the addresses of variables and pointers?
A pointer is a variable whose value is the address of another variable
So if i take an integer variable called "X" and an Integer pointer variable called "Y", Y will be equal to the address of X, not the value of X. And note that to store an address of an Integer variable, the pointer variable also should be an Integer pointer. Which means the types of the pointer variable and the variable should be the same and it's obvious.
It's more like some one is trying to install an Android app on a Apple phone which wont work. You should install an Android app on a Android phone.
Given below is a simple diagram which explains the simple theory behind the pointers.
We have an integer variable X which has an address of 200 in the memory ( in real environment it may not 200 ). And there's a pointer variable called Y which has the address of X which is 200.
No comments:
Post a Comment