0
need explonation in detail
step by step needed, confused #include <stdio.h> void fun(int *i,int *j) { *i=*i * *i; *i=*j * *j; } int main() { int i=2,j=3; fun(&i,&i); printf("%d,%d",i,j); return 0; }
3 ответов
+ 3
#include <stdio.h>
void fun(int *i,int *j)// i and j store the value of main method i variable means i=2 and j=2
{
*i=*i * *i;//i=4
*i=*j * *j;//i=16
}
int main()
{
int i=2,j=3;
fun(&i,&i);//call by reference fun(addr of i,addr of i)
printf("%d,%d",i,j);//16 and 3
return 0;
}
Explanations:
i=2
fun(&i,&i);
fun(int *a , int *b) is stored the address of main method i variable and if the value of a and b change in fun() than the value of i is also change
*a=*a**a;//value of i =4
*a=*b**b;//value of i=4 than b=4*4 ,*a =16 and now i is 16
+ 1
Yes
0
so here single variable address is assinged to two different pointers(i and j) right