EEVblog Electronics Community Forum
Electronics => Beginners => Topic started by: khatus on May 19, 2020, 04:15:11 pm
-
Hello guys i have some question regarding C pointer.
(https://i.ibb.co/kyft4rK/joined-Copy.png) (https://ibb.co/DbyZ964)
Here What is meant by mixed call here?
Having trouble understanding the meaning of the red lines? Can anyone explain?
-
Mixed call is not standard terminology. It seems to have been invented by the author. In a sense there is nothing mixed, in C all arguments to functions are passed by value. So in order to be able to modify the actual variable rather than just a copy of the value you need to pass the address of the variable so that the callee can modify the original variable.
-
Forget "mixed call" it's just something they made up to point out the difference from other examples :)
To break it down slightly:
areaperi ( int r, float *a, float *p )
Let's start with r.
r is passed as regular data so the function is only aware of what the value is. Not where it's stored in the program. (ie. I called you on the phone and told you a number, I'm deaf so you can't tell me the answer)
a and p are both pointers.
These are passed as an address. (ie. I called you on the phone and told you where my mailbox is located. Remember I'm deaf so I can't hear you. You can do whatever you want to it and and I'll come back later and check what you've done)
Difference is that I can't know what you've done to that number after the call. I can, however, check what you stored in my mailbox
-
its clearly explained in the text about the author's term... "in the sense radius.. (is passed by value) and area and perimeter.. (are passed by reference).. passed by value means, technically speaking, the callee function will make another copy of the passed variable locally so any modification will only be made to that copy, not the original variable (from caller function). passed by reference (pointer), the callee function will directly modify the variable passed from the caller function.
-
In some languages, like Ada, procedures (functions) can have "IN", "OUT", or "INOUT" parameters. In a normal function with only "IN" parameters, the only output of the function is its result or return value, the object that replaces the function call when it's used in an expression. If there are "OUT" parameters, the procedure can store values into them as additional outputs. An "INOUT" parameter passes a value into the procedure and can also receive one of the procedure's outputs.
C and C++ do not have formal syntax for "OUT", or "INOUT", but achieve the same effect using pointer and reference arguments. By storing through a pointer given as an argument, a C function can output into the object addressed by the pointer. By assigning to a reference argument, a C++ function can output to the object passed as the argument. These "functions with additional outputs" are not functions in the math sense, since they are not necessarily idempotent.