Why its shows error while try to pass the value as normal interger a and b into the function update instead of passing ptr var? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why its shows error while try to pass the value as normal interger a and b into the function update instead of passing ptr var?

I'll mention code here plz someone help me to fig out the doubt #include<studio> void update(int *a ,int *b){ *a+=*b; *b=abs(*a -(2* *b));} int main(){int a,b; //int *pa=&a,*pb=&b; Scanf("%d %d", &a, &b); //update(pa,pb); Update(a,b); Return 0; }

25th Apr 2019, 5:46 PM
Sudha
Sudha - avatar
1 Answer
+ 3
please kindly write your code on code play ground and link it here edit, you need to pass the address of the variable as parameter in the function, wince its not an array /*Why its shows error while try to pass the value as normal interger a and b into the function update instead of passing ptr var? I'll mention code here plz someone help me to fig out the doubt */ #include<stdio.h> #include <stdlib.h> int update(int *a ,int *b){ *a+=*b; *b=abs(*a -(2* *b)); return *b;} int main(){int a,b; //int *pa=&a,*pb=&b; scanf("%d %d", &a, &b); //update(pa,pb); printf("%d",update(&a,&b)); return 0; } thats your code now working fine
25th Apr 2019, 7:45 PM
✳AsterisK✳
✳AsterisK✳ - avatar