You can do a = b = abc(); Or change the code so that it reads a = abc( &b );
when i tried your way, it is printing the value of p and p is equal to square of x, i want to print the value of x for b that i've assigned in line 15 ( sorry , in my first post i wrote line number 16.)
The variable b in main() is passed to function abc() by reference, which means that any changes made to it in abc() will also be made in main(). The parameter x in abc() is a pointer to the variable b in main().
So if you want to print the value of x that is in abc() just print the value of b that is in main(). Even though they have different names, since x is a pointer, printing the value os *x is the same as printing the value of b. Clear as mud?
Add a line of code in abc() to print the value of x and you will see what I mean: printf("x = %d\n", *x); Note the star is required because x is a pointer.
i've whatever you said but we haven't learn more than the basics of the functions (only learned how to create a function)
your program is really complicated because we haven't learn pointers ..and i really don't know where in your program you declare a function..because we've learned to use statement terminator at the end of line where we declare a function. i.e
this is the declaration but in your program where is the declaration ?? sorry but we did'nt study more than that that is why i am asking these silly questions.
see this program..
this is really simple code..how can i implement pointer in this code without any complications ?
when i am writing.
That is called a function prototype, which is used to forward declare the function so that the compiler knows what it is, it's return value, and its parameters.
Function prototypes are unnecessary if the function actually appears before it is used, as in the example I posted. You may code the prototype, but it is not required in that case.
The code you posted does not compile because you did not code the function prototype correctly. Change it to this: int abc(float *b); Now change the actual function like this:
int abc(float *x)
scanf ("%f",x); // NO & symbol here because x is already a pointer
// Here is another way to code it
// maybe it makes more sense to you
// what it is doing.
p = *x;
return p * p;