| | |
Problem About Pointers
Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Aug 2004
Posts: 11
Reputation:
Solved Threads: 0
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 ?
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 ?
![]() |
Similar Threads
- Problem with pointers (C++)
- The Problem with Pointers (C++)
- swapping with pointers ... (C)
- Problem with pointers (C++)
- Converting Struct to class lost with pointers (C++)
Other Threads in the C++ Forum
- Previous Thread: complex arithmatic
- Next Thread: PSP Help.
Views: 2926 | Replies: 4
| Thread Tools | Search this Thread |
Tag cloud for C++
6 add api array arrays beginner binary bitmap c++ c/c++ calculator char class classes code compile compiler console conversion convert count data delete desktop directshow dll encryption error file forms fstream function functions game getline givemetehcodez google graph homeworkhelper iamthwee ifstream input int integer java lazy lib linkedlist linux loop looping loops map math matrix memory microsoft newbie news node number output parameter pointer problem program programming project proxy python random read recursion recursive reference return sort string strings struct studio system template templates test text tree unix url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets





