Question:
Call the value, return the value and pass the value in programming?
Pankaj
2011-06-09 19:41:14 UTC
I have read call a function or value or return a vaue or pass the object etc. in many languages. Can anybody plz explain these three in simple words? What is actually meaning of these in programming language like C++? I m very confused...
Three answers:
?
2011-06-09 20:05:08 UTC
Wikipedia has an impressively comprehensive article on this, http://en.wikipedia.org/wiki/Evaluation_strategy



In languages like C++ it means when you make a function call, the *values* of the function arguments are passed into the function body, not the arguments themselves, not their names, not anything else. The values of the arguments are copied and the function deals with those copies.



Say, there is an object called i that has the value 2, created with "int i = 2;", and you call a function, say, "f(i)", the value "2" is copied out of the object i, and into the function. The object i is not affected by such function call, and the function has no knowledge of any "i", it just sees the 2, the value.
?
2011-06-10 02:52:50 UTC
Every function has its own context. That is, if you have a variable Count in your main(), it is entirely different from the variable Count in your checkfile(). This is a good thing. It means you're sure some other part of your program can't accidentally change your data.



Likewise with objects. Each object has its own context, and an object created in one function is not available to another function.



In order to share data between functions, you pass the variable or object. When you call a function, you call it such as in checkfile(FilePath, FileName). The function accepts the data, and can even call it different names internally. When the function finishes, it can "return" a value as in ErrorCode = checkfile(FilePath, FileName). It can also modify the original object or variable, if allowed.
oops
2011-06-10 02:49:01 UTC
Why don't you just start studying a programming language? These things will then become evident to you.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...