#include<stdio.h>
int sum(int,int);
int main()
{
    int a=5;
    int b=6;
    int res;
    res=sum(a,b);
    printf("\n%d\n%d\n",a,b);
    printf("%d",res);

}
int sum(int x,int y)
{
    x=x+1;
    y=y+3;
    return y;
}

This is a sample program where my a and b values didint change and the result of modified y (ie)9 is returned back to main program...but my doubt is if iam doing the same program using pointers i am getting "CONVERITNG INT** INT* is NOT POSSIBLE???CAN U explain ....thank you..........

#include<stdio.h>
int* sum(int,int*);
int main()
{
    int a=5;
    int *b;
    *b=6;
    int *res;
    res=sum(a,&b);
    printf("\n%d\n%d\n",a,*b);
    printf("%d",*res);

}
int* sum(int x,int *y)
{
    x=x+1;
    *y=*y+3;
    return (&y);
}

iam very weak in pointers can you suggest me how to improve my skills in pointers........thanks in advance :)

This line:

int *b;

just tells the machine that address b will point to integer, and what memory adress contains b we do not know. Before the line

*b=6;

you should allocate place in the memory to put number 6 there:

b=new int[1];

. So, it should be like:

int *b;//Declare address for integer
b=new int[1];//Allocate memory for integer and assign its address to b
*b=6;//Put 6 into this part of memory
delete b;//Do not forget this line :), it cleans memory
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.