This post discusses the basics of pointers and Structures.
POINTERS:
A pointer stores the address of a variable. It can also be used to store the address of an array, structure(which is a user defined variable), function and even a pointer.
Declaration:
A pointer for custom type variables is defined as:
int * p(where p is the pointer we are using)
float *p
char *p
A pointer for a structure:
Lets say the structure is named struct student {
int m_iinfo;
char m_pname;}
the pointer will be defined as struct student *p;
A pointer to a function:
A pointer to a function is defined and can be used only for the same TYPE of functions.
Same type functions are those who have the same return types and have same arguements.
Example:
int func(int x, int y) be the function.
pointer to the function will be : int (*p)(int x, int y);
Always remember the braces for the pointer p. If there are no braces, it will be treated as a function p whose return type is an integer pointer and arguements are integers. This type of notation is extensively used for interface with OS and registers to point to a particular function.
Pointers to pointers:
int *p is a pointer to an integer. We can also create q which is a pointer to an integer pointer.
int ** q defines a pointer q to an integer pointer.
it is equivalent to a two dimensional array. This type of declaration is called COMPLEX DECLARATION.
Subscribe to:
Post Comments (Atom)
2 comments:
do you think writing at this level of understanding would help?
hi rocky,
Yes, it certainly is.
its better to clarify your understading by putting in words rather than thinking in dark and feeling that you know!!
how many people really understand ptr_to_func or have low level understanding of ptrs.
Let him write articles..
its part of his growth..
Growth should be encouraged...
I think you are getting my point.
thx
suds
Post a Comment