+ 4

Someone can help me ? How to change the value of ten times of it's current value???

program to change the value of a variable to ten times of its current value write function and pass the value by refrence

12th Jun 2021, 7:05 AM
Sayyad Faujiya
Sayyad Faujiya - avatar
16 ответов
+ 5
/*write a program to change the value of a variable to ten times of its current value write a function and pass the value by reference */ #include<stdio.h> void change(int *ptr) { (*ptr)*=10; } int main() { int a; printf("Enter the value of a :\n"); scanf("%d",&a); int *ptr=&a; printf("the current value of a is =%d\n",a); change(ptr); printf("now,the value of a is =%d",*ptr); return 0; }
12th Jun 2021, 7:48 AM
Sayyad Faujiya
Sayyad Faujiya - avatar
+ 3
Thanks I got it.. 😊
12th Jun 2021, 7:27 AM
Sayyad Faujiya
Sayyad Faujiya - avatar
+ 3
This parentheses include for code readability ... 🙂.. And I confused to pointer * operator and multiplication *operator.. So it's ok.
12th Jun 2021, 8:12 AM
Sayyad Faujiya
Sayyad Faujiya - avatar
+ 2
Please post your attempt here. Hint: try to use the *= assignment operator.
12th Jun 2021, 7:16 AM
Calvin Thomas
Calvin Thomas - avatar
+ 2
https://code.sololearn.com/cjXlsHIm5MXV/?ref=app Try this, Explanation : The function tenTimes() take argument as address of your variables, we can find address using '&' and we can go to that address using '*' , so we go to the address of variable and changes its value! hope you understand
12th Jun 2021, 7:48 AM
Abhiyantā
Abhiyantā - avatar
+ 1
Sayyad Faujiya Exactly, but you could simplify it further by removing the unnecessary parentheses around the de-referenced pointer 'ptr'.
12th Jun 2021, 8:08 AM
Calvin Thomas
Calvin Thomas - avatar
+ 1
I posted my code..you can see in my code bits.. 🙂
12th Jun 2021, 8:12 AM
Sayyad Faujiya
Sayyad Faujiya - avatar
+ 1
Program to change the value of a variable to ten Times of its current value write and pass the call by value
9th Nov 2021, 1:26 PM
Pratik Nikam
0
this is the simpler way to write this code #include<stdio.h> void change(int *i); int main(){ int a=7; printf("The current value of a is %d\n", a); change(&a); printf("The value of a is %d\n",a ); return 0; } void change(int *i){ (*i)*=10; }
17th Apr 2022, 5:59 AM
Syed mohammad Arsalan
0
#include<stdio.h> void change(int *i); int main(){ int a=7; printf("The current value of a is %d\n", a); change(&a); printf("The value of a is %d\n",a ); return 0; } void change(int *i){ (*i)*=10; }
17th Apr 2022, 6:00 AM
Syed mohammad Arsalan
0
call by value does not change the current value see this, #include<stdio.h> void change(int i); int main(){ int a=7; printf("The current value of a is %d\n", a); change(a); printf("The value of a is %d\n",a ); return 0; } void change(int i){ (i)*=10; }
17th Apr 2022, 7:01 AM
Syed mohammad Arsalan