GIDForums  

Go Back   GIDForums > Computer Programming Forums > C Programming Language
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 28-Aug-2008, 03:13
nilusha6 nilusha6 is offline
New Member
 
Join Date: Aug 2008
Posts: 12
nilusha6 is an unknown quantity at this point
Smile

Using pointer as a parameter


I have a pointer variable in main function.(linked list)

i need to pass that pointer to a function.
in the function,it will change the pointer contents.(added new items)

But i need the original pointer as it is.
so, how can I use a copy of that pointer(link list) within that function.

actually i need to getseveral paths in a diagrem,path is starting from (0,0).
destination is (7,7).
I have to find all the posible paths.Thats y i used linked list.

So,I try to start from frist position. when path is divided , i need to get two different paths.So, i ll try to use that stroed linked list's 2 copies and want to store the rest.

So,can any 1 gv me any idea please.
  #2  
Old 28-Aug-2008, 09:50
fakepoo fakepoo is offline
Regular Member
 
Join Date: Oct 2007
Posts: 713
fakepoo is a jewel in the roughfakepoo is a jewel in the roughfakepoo is a jewel in the rough

Re: Using pointer as a parameter


You should probably pass a pointer to that pointer:

CPP / C++ / C Code:
void AllocateArray( int **ppArray, int size )
{
  *pArray = (int*)calloc(size,sizeof(int));
}

int main()
{
  int *pArray;
  AllocateArray( &pArray, 10 );
  // ...
  free(pArray);
  return 0;
}

Or, if it is fairly simple, you could pass the pointer as an argument to the function and return it from the function like so:
CPP / C++ / C Code:
int *EditPointer( int *p )
{
  // do what you need to do to p
  return p;
}

int main()
{
  int x;
  int *p;
  p = &x;

  p = EditPointer( p );

  return 0;
}
 
 

Recent GIDBlogProblems with the Navy (Chiefs) by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
MACRO to detect big / little endian ahbi82 C Programming Language 14 26-Aug-2007 11:33
Passing strings by reference odrium C++ Forum 7 18-Jul-2007 23:27
Help with syntax errors PeteGallo C Programming Language 7 08-Aug-2005 21:30
[Tutorial] Pointers in C (Part II) Stack Overflow C Programming Language 0 27-Apr-2005 18:36

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 15:56.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.