| | |
pointer
![]() |
•
•
Join Date: Jul 2004
Posts: 1
Reputation:
Solved Threads: 0
POINTER
INTERDUCTION::
Pointer is a variable that can hold address value.
Pointer to integer is not type of integer
A questain may arises to your mind that why
Pointer variable is not declare like “pointer� like
Integer as “Int� .
Here is a problem science pointer can point any
Data type so compiler need to know what kind
Data type the pointer points
So rather than
Representing
pointer ptr;
it represented as
int *ptr;
char *ptr1;
etc…
PROPERTIES::
Consider this example
L1: int n;
L2:int *ptr;
L1 interprets as declare n as integer type
Where
L2 interprets a sptr is a pointer to a integer
CASE1:
Now consider this two line
L1: int n1,n2;
L2 int * p1,p2;
L1: interpreted n1,n2 are both integer type variable
L2:interpreted that p1 is pointer to a integer where
P2 is only an integer CASE2:
Consider this representation
Int **….ptr;
It means that ptr is a pointer to a pointer…………..ponts to a int
CASE3:
Consider this example
L1: int *(ptr)[2]=arrptr;
L2 int * arr[2];
L1 interprets as a pointer to 2 integers
Where
L2 interprets array of pointers of 2 integers
VOID POINTER:
A single pointer that can holds address of different
Data type is known as void pointer
It declare as
Void *ptr;
Consider an example:
Int I;
Float f;
Int *ptr;
Void vptr;
Ptr = &I; // no error
Ptr = &f; // error
Vptr = &I; // no error
Vptr = &f; // no error
NB::
We can declare a reference to a pointer ,but we can.t
Declare a pointer to reference &can.t declare a
Reference to reference
FUNCTION POINTER:
Function pointer is confusing when we interpreting
When we interpreting a declaration
It is used in virtual function table &in some template
Ex:
Int (*ptr) (int);
It mean that ptr is a pointer which point to a function
Takng an argument of integer type & return a int type
EX2:
Int * * (*ptr) ( int, int)
It declare that ptr is a pointer to a function which
Takes two int return a pointer to pointer to a integer
CONSTANT POINTER:
Constant is a key word which prevents the reinitalisation
Of value of a variable
Consider this example
Const int i=1;
Int const j=2;
In this case both declaration I, j are constant intEx:
Int n;
Int * const a=&n;
It declare a constant pointer to a integer
If we declare as
Const int *const a=&n;
That mean we neither can change the pointer
Value & int value`
TYPEDEF DECLARATION:
Typedef key word allow to programmer to
Overcome type rule that mean
If we declare
typedef int *ptr;
Ptr p1,p2;
That mean here p1 & p2 are pointer
Which store address of intiger
In a complicate declaration first find the innermost “(�
Parenthesis then identify the variable name move right when
A �)� parenthesis is found move left jumps the left�(“
This procedure continues till the end
Ex:
Int * ( * ( * ptr) ( int ) ) [5]
Ans: here ptr is the variable
So ptr is a pointer to a function that takes an integer argument
And returns a pointer to a array of 5 pointers of integer type
I feel this small tutorial helps to understanding
the pointer concept
Nihar ranjan Nayak
Mca(04) utkal university
[/COLOR] Email: niharwait@yahoo.com
Orissa,India
INTERDUCTION::
Pointer is a variable that can hold address value.
Pointer to integer is not type of integer
A questain may arises to your mind that why
Pointer variable is not declare like “pointer� like
Integer as “Int� .
Here is a problem science pointer can point any
Data type so compiler need to know what kind
Data type the pointer points
So rather than
Representing
pointer ptr;
it represented as
int *ptr;
char *ptr1;
etc…
PROPERTIES::
Consider this example
L1: int n;
L2:int *ptr;
L1 interprets as declare n as integer type
Where
L2 interprets a sptr is a pointer to a integer
CASE1:
Now consider this two line
L1: int n1,n2;
L2 int * p1,p2;
L1: interpreted n1,n2 are both integer type variable
L2:interpreted that p1 is pointer to a integer where
P2 is only an integer CASE2:
Consider this representation
Int **….ptr;
It means that ptr is a pointer to a pointer…………..ponts to a int
CASE3:
Consider this example
L1: int *(ptr)[2]=arrptr;
L2 int * arr[2];
L1 interprets as a pointer to 2 integers
Where
L2 interprets array of pointers of 2 integers
VOID POINTER:
A single pointer that can holds address of different
Data type is known as void pointer
It declare as
Void *ptr;
Consider an example:
Int I;
Float f;
Int *ptr;
Void vptr;
Ptr = &I; // no error
Ptr = &f; // error
Vptr = &I; // no error
Vptr = &f; // no error
NB::
We can declare a reference to a pointer ,but we can.t
Declare a pointer to reference &can.t declare a
Reference to reference
FUNCTION POINTER:
Function pointer is confusing when we interpreting
When we interpreting a declaration
It is used in virtual function table &in some template
Ex:
Int (*ptr) (int);
It mean that ptr is a pointer which point to a function
Takng an argument of integer type & return a int type
EX2:
Int * * (*ptr) ( int, int)
It declare that ptr is a pointer to a function which
Takes two int return a pointer to pointer to a integer
CONSTANT POINTER:
Constant is a key word which prevents the reinitalisation
Of value of a variable
Consider this example
Const int i=1;
Int const j=2;
In this case both declaration I, j are constant intEx:
Int n;
Int * const a=&n;
It declare a constant pointer to a integer
If we declare as
Const int *const a=&n;
That mean we neither can change the pointer
Value & int value`
TYPEDEF DECLARATION:
Typedef key word allow to programmer to
Overcome type rule that mean
If we declare
typedef int *ptr;
Ptr p1,p2;
That mean here p1 & p2 are pointer
Which store address of intiger
In a complicate declaration first find the innermost “(�
Parenthesis then identify the variable name move right when
A �)� parenthesis is found move left jumps the left�(“
This procedure continues till the end
Ex:
Int * ( * ( * ptr) ( int ) ) [5]
Ans: here ptr is the variable
So ptr is a pointer to a function that takes an integer argument
And returns a pointer to a array of 5 pointers of integer type
I feel this small tutorial helps to understanding
the pointer concept
Nihar ranjan Nayak
Mca(04) utkal university
[/COLOR] Email: niharwait@yahoo.com
Orissa,India
![]() |
Similar Threads
- *Pointer program problem. (C++)
- How to access a Public Pointer value of a class directly? (C++)
- pointer to member? (C++)
- pointer to some code (C++)
- Assign content to a function pointer (C)
- Change Out Your Pointer Scheme (Windows tips 'n' tweaks)
Other Threads in the C Forum
- Previous Thread: Cross-compiler for C?
- Next Thread: Does anyone know what type of file this is?
| Thread Tools | Search this Thread |
#include * adobe ansi api array asterisks binarysearch centimeter changingto char character cm copyimagefile cprogramme creafecopyofanytypeoffileinc csyntax database directory dynamic execv feet fgets file fork function getlasterror getlogicaldrivestrin givemetehcodez global grade gtkgcurlcompiling gtkwinlinux hacking hardware highest histogram ide include incrementoperators infiniteloop input interest kernel keyboard kilometer license linked linkedlist linux linuxsegmentationfault list locate logical_drives looping loopinsideloop. lowest match matrix meter microsoft motherboard mqqueue number odf opendocumentformat opensource owf pattern pdf performance pointer posix probleminc process program programming radix recursion recv repetition research reversing segmentationfault sequential single socket socketprograming standard string systemcall threads turboc unix user voidmain() wab whythiscodecausesegmentationfault windows.h windowsapi





