943,519 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 3264
  • C++ RSS
Aug 13th, 2004
1

Problem About Pointers

Expand Post »
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.
Similar Threads
Reputation Points: 11
Solved Threads: 0
Light Poster
Sukhbir is offline Offline
31 posts
since Jul 2004
Aug 13th, 2004
1

Re: Problem About Pointers

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 ?
Reputation Points: 11
Solved Threads: 0
Newbie Poster
stg110 is offline Offline
11 posts
since Aug 2004
Sep 7th, 2004
0

Re: Problem About Pointers

there can be pointer to pointer.
int a=25;
int*b=&a;
int**c=&b;
Reputation Points: 10
Solved Threads: 1
Newbie Poster
let us c is offline Offline
17 posts
since Aug 2004
Sep 7th, 2004
0

Re: Problem About Pointers

there can be pointer to pointer.
.............
int a=25;
int*b=&a;
int**c=&b;
............
here c is pointer to b.
Reputation Points: 10
Solved Threads: 1
Newbie Poster
let us c is offline Offline
17 posts
since Aug 2004
Sep 7th, 2004
0

Re: Problem About Pointers

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
Reputation Points: 10
Solved Threads: 1
Newbie Poster
let us c is offline Offline
17 posts
since Aug 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: complex arithmatic
Next Thread in C++ Forum Timeline: PSP Help.





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


Follow us on Twitter


© 2011 DaniWeb® LLC