+ 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
11 Antworten
+ 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;
}
+ 3
Thanks I got it.. 😊
+ 3
This parentheses include for code readability ... 🙂.. And I confused to pointer * operator and multiplication *operator.. So it's ok.
+ 2
Please post your attempt here. Hint: try to use the *= assignment operator.
+ 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
+ 1
Sayyad Faujiya Exactly, but you could simplify it further by removing the unnecessary parentheses around the de-referenced pointer 'ptr'.
+ 1
I posted my code..you can see in my code bits.. 🙂
+ 1
Program to change the value of a variable to ten Times of its current value write and pass the call by value
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;
}
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;
}
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;
}