Can someone please understand the difference between parameters passed in C ? According to Professor notes there are 4 different ways to pass the parameter
- Call-by-value
- Call-by-address (pointer)
- Call If you can kindly give an example, I appreciate it, and your work will be appreciated.
-
call-by-value
Passing the value of a function as the parameter if the function modifies the variable, the actual variable will not change .
Zero Funny 1 (Intmuprum) {myParam = 4; } Zero main () {int myValue = 2; Fun1 (myValue); Printf ("myValue =% d", myValue);
myValue
will always be 2. -
Call-by-address (pointer)
Fun to zero 1 (Int * MyMuram) {* MyParam = 4; } Zero main () {int myValue = 2; Fun1 (& myValue); Printf ("myValue =% d", myValue); }
Here we are giving the address of
myValue
tofun1
. Therefore the value ofmyValue
will be 4 at the end ofmain ()
. -
Call-by -Lyas
According to my understanding there is no surname in C. It should be the C ++ reference mechanism.
-
global variable / static variable
The general location accessible by a collar and cali functions is both the calling The ones and colleagues will be able to access and modify them.
int myValue = 2; Zero Funny 1 () {myValue = 4; } Zero main () {myValue = 2 fun1 (); Printf ("myValue =% d", myValue); }
As you can guess, the value of
myValue
will be 4 at the end ofmain ()
.
Hope it helps.
No comments:
Post a Comment