Hi, I didn't write c from a long time but as far as I remember the following
should work:

What you have done is sending a pointer by value, you send a copy of its
value to the function, that is good only if you want to change the value of
the thing the pointer points to, but if you want to change the what the
pointer points to, you have to make a pointer to the pointer and send the
pointer's address by reference to the function .

Hi friends,

Plz help me . I am not good in pointer in c.

#include<iostream>
using namespace std;
void fun(char **p)// a pointer to a pointer , so that you receive the
address of the pointer so you can change it.
{
char a[]="yet another";
*p=a; //Make the value of the pointer to the pointer (meaning the value of
the pointer sent, the address itself) equal to a.

}
main()
{
char *p="hellow world";
fun(&p); //send the address of the pointer.
cout<<p;
system("pause");
}

I was expecting output is "yet another". but I got "hellow world".

#include<iostream>
using namespace std;
void fun(int *c)
{
c[1]=56;
}
main()
{
int b[]={2,3,5};
int *c=b;
fun(c);
cout<<c[1];
system("pause");
}
but in case of interger. i was expecting value of c[1] equal to 56. I got
56.

can any one explain it?

---------------------------------
Yahoo! Answers - Get better answers from someone who knows. Tryit now.

[Non-text portions of this message have been removed]

 



[Non-text portions of this message have been removed]

Reply via email to