Pointers
Before you start: To learn how to compile a c programme click here or click here
Pointers are the difficult feature of C for beginners .Other languages have Pointers but only few use them as frequently as C does.But Beginners should have to remember that C’s clever use of Pointers make C a excellent language .
Most of the Beginners feel difficulty in the Pointers terminology rather then the actual concepts of pointers.
Actually when a C programmer says that this variable is a pointer, what does it means ??
It seems hard to see how a variable can “point” to something/or in a direction.
TO examine let us make a program
programming code for pointers |
- We should include standard input/output header file (stdio.h).
- must define a main function in program.
- In this program we define two integer type variable ,one is a(simple holds a integer value) and another is *b (it is a integer pointer variable which can holds the address of any variable).
- Assign a value in a.
- Assign the address of a in b.(as we know b is a variable of pointer type).
- Print the address of a by &a and b (by both methods we can find the address )
- Print the value of a by simple printf(“%d”,a) method and by printf(“%d”,*b) method(pointer’s method).
output:
Output of above proram |
As we can see the output of previous program
by both the method address is same and also by both methods value is also same.
note that printing the value of *(&a) give same result as printing the value of a.
No comments:
Post a Comment