need explonation in detail | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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; }

4th Mar 2020, 4:25 AM
Reiner
Reiner - avatar
3 Answers
+ 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
4th Mar 2020, 5:44 AM
Prathvi
Prathvi - avatar
+ 1
Yes
5th Mar 2020, 6:41 AM
Prathvi
Prathvi - avatar
0
so here single variable address is assinged to two different pointers(i and j) right
5th Mar 2020, 6:38 AM
Reiner
Reiner - avatar