943,641 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 4996
  • C RSS
Jul 9th, 2004
0

pointer

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
NIHAR RANJAN is offline Offline
1 posts
since Jul 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: Cross-compiler for C?
Next Thread in C Forum Timeline: Does anyone know what type of file this is?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC