pls tell what is the difference between this two
1)taking a initger (or any fundamental data type) pointer in the main function and then send it to some funtion as parameter.
int *p;
function(p);

2)taking a intiger and sending its adress to any function.
int p;
function(&p);

will both do the same?
if not the what is the advantage of both of this.
i have another question.
in some link list program i saw that they have taken a structure pointer in the main function and have sent the adress of that pointer to the funtion.
main()
{
struct node *p;
function(&p);
}
function(struct node **p);
i am not under standing why they have taken pointer of pointer.why i cant send p as a parameter.
then thecode will be like this
main()
{
struct node *p;
function(p);
}
function(struct node *p);
what is the problem in this?
pls reply as early as u can.coz i am stucked here.

Pls anyone kindly answer?

pls tell what is the difference between this two
1)taking a initger (or any

fundamental data type) pointer in the main function and then send it to some funtion as parameter.
int *p;
function(p);

2)taking a intiger and sending its adress to any function.
int p;
function(&p);

No particular difference.
eg:

func(int *p)
{
   *p++;
}

func1()
{
  int a = 2;
  int *p = &a;
  func(p);   // sending address of a
}

func2()
{
  int a = 2;
  func(&a);  // sending address of a
}

As you can see, in both places we are just sending the address.

As far as the second question is concerned, you are right.

void func(struct samp *ptr)
{
    /* statements here */
}
void func1()
{
   struct samp *p = &var; // where var is a variable of samp
   func(p);
}

This is absolutely fine. Although im not sure in what context you saw that piece of code.

is there noone to reply??

thanks its a great help.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.