User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 456,555 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,528 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums
Views: 2444 | Replies: 4
Reply
Join Date: Jul 2004
Posts: 31
Reputation: Sukhbir is an unknown quantity at this point 
Rep Power: 5
Solved Threads: 0
Sukhbir Sukhbir is offline Offline
Light Poster

Problem About Pointers

  #1  
Aug 13th, 2004
1.
int *f()
{
int *m=(int *)malloc(2);
return m;
}
WHY THIS POINTER TO INT TREATED AS A GLOBAL VARIABLE.
2.can a pointer points to another pointer
like that
int *p,i=2;
int *q;
p=&i;
q=p;
IS IT RIGHT.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Aug 2004
Posts: 11
Reputation: stg110 is an unknown quantity at this point 
Rep Power: 5
Solved Threads: 0
stg110 stg110 is offline Offline
Newbie Poster

Re: Problem About Pointers

  #2  
Aug 13th, 2004
about the second question yes you can use pointer to refrence to another pointer and this is the method used in dynamic allocation of multi dimintion aray you can write :
void a2d(int i,int j)
{
int **t =new int*[i] ;//rows
for(int k=0;k<i;k++)
t[k]=new int[j] ; //col
}

but i do not understand the first question but notice that the pointer is a refrense mean that if u pass a pointer of int to an function it does not take a copy from the int it takes a copy of the refrence to the int so if u change the int value it will be changed and u can not retain the previous value for example :
main()
{
int *i=new int ;
*i=2;
fun (i) ;
cout<<*i;
getch();
}
void fun (int *m)
{
*m=3;
}
the result of the cout will be 3 is that what u mean ?
Reply With Quote  
Join Date: Aug 2004
Location: india,AP
Posts: 17
Reputation: let us c is an unknown quantity at this point 
Rep Power: 5
Solved Threads: 1
let us c's Avatar
let us c let us c is offline Offline
Newbie Poster

Re: Problem About Pointers

  #3  
Sep 7th, 2004
there can be pointer to pointer.
int a=25;
int*b=&a;
int**c=&b;
Reply With Quote  
Join Date: Aug 2004
Location: india,AP
Posts: 17
Reputation: let us c is an unknown quantity at this point 
Rep Power: 5
Solved Threads: 1
let us c's Avatar
let us c let us c is offline Offline
Newbie Poster

Re: Problem About Pointers

  #4  
Sep 7th, 2004
there can be pointer to pointer.
.............
int a=25;
int*b=&a;
int**c=&b;
............
here c is pointer to b.
Reply With Quote  
Join Date: Aug 2004
Location: india,AP
Posts: 17
Reputation: let us c is an unknown quantity at this point 
Rep Power: 5
Solved Threads: 1
let us c's Avatar
let us c let us c is offline Offline
Newbie Poster

Re: Problem About Pointers

  #5  
Sep 7th, 2004
there can be pointer to pointer.
.............
int a=25;
int*b=&a;
int**c=&b;
............
here c is pointer to b and b is pointer to a.
value of acan be accesed in two ways.ie by both the pointers.


if i am wrong anywhere please tell me.thank you :p
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb C++ Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the C++ Forum

All times are GMT -4. The time now is 5:30 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC