473,396 Members | 1,945 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

What does it mean when a function returns an argument?

I understand that when a function takes an argument, there is an argument called to the function, which it then manipulated by/put through the function. I do not really understand what it means if a function takes and returns arguments... Does it mean that it gives a value back? But don't functions that take no arguments also take a given something and spit something out?
Jan 5 '17 #1

✓ answered by stdq

Hi! A function may, or may not, return something to the callee. This "something" might be, coincidentally, one of the arguments the function received when it was called. It is also possible that a function takes no arguments and returns something, for example the rand() function, which generates pseudorandom numbers.

3 1356
stdq
94 64KB
Hi! A function may, or may not, return something to the callee. This "something" might be, coincidentally, one of the arguments the function received when it was called. It is also possible that a function takes no arguments and returns something, for example the rand() function, which generates pseudorandom numbers.
Jan 5 '17 #2
Ok so a function returns nothing when there is just something done? Like something is printed? If it is calculated and printed within the function does that mean it returns nothing even then? And it only returns something when some kind of data or value that has been manipulated within the function is returned to main()? Oh and if it takes no arguments there's no need for a value to be entered into the parameters? That makes a lot more sense if I am understanding this correctly! Thank you!
Jan 5 '17 #3
weaknessforcats
9,208 Expert Mod 8TB
Functions don't return arguments. But they do return data to the calling function by using an argument.

Case A: Provide the Address of a Variable in the Calling Function:


Expand|Select|Wrap|Line Numbers
  1. void CallingFunction()
  2. {
  3.  
  4.     int a = 0;  
  5.     CalledFunction(&a);
  6.  
  7.  
  8. }
  9.  
  10. void CalledFunction(int* result)
  11. {
  12.     *result = 10;  << this goes into the calling function variable.
  13.  
  14. }
  15.  
Case B: Provide the address of a Pointer to the called function:

Expand|Select|Wrap|Line Numbers
  1. void CallingFunction()
  2. {
  3.     char* str = 0;
  4.     CalledFunction(&str);
  5.  
  6.  
  7. void CalledFunction(char** result)
  8. {
  9.    *result = malloc(100 * sizeof(char));  << the memory address is in the calling function pointer
  10.  
  11.    strcpy(*result, "May the force be with you.");  << the called function copies into that memory.
  12. }
  13.  
Notice in these cases the called function has no return statement. The return staement is only to place a value in the return type of the function. Using the return type is only meaningful of the called function is on the right side of an assignment operator.
Jan 6 '17 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Charles Hixson | last post by:
I'm getting a list that I build which when printed is displaying, well, e.g.: d = << , 'Do', 'not', 'remove', 'thi', '.', ] >> Clearly I have a problem with the truncation of the final this, but...
4
by: QQ | last post by:
for example ~CcMessage() {} Thanks a lot! I am a beginner for C++, so please forgive my stupid questions
6
by: wintaki | last post by:
Given int x; What does x evaluate to? If x is 0, it equals 0x31, the ascii value of '1'. So for some reason, x evaluates to *(y+x) where x is a non pointer/array type.
2
by: SMichal | last post by:
Hi, I'm starting from my application simple bat data...test.bat. This file (test.bat) should start another aplication app.exe. I'm starting the test.bat from my application with Start() method of...
9
by: plusk1008 | last post by:
I have finals next week and I am stuck on one question on my review sheet for excel. So once again I beg: Please, please, please, please, please, please, please, please, please, please someone help...
2
by: mantrid | last post by:
in some php script ive seen $something==@$somethingelse whereas something==$somethingelse works the same what does the use of the @ do? Sorry if this is a stupid question
4
by: dolphin | last post by:
Hi All I read a .cpp files,find that static void fun(void){......} int main() { .......... } What does this static function mean?Is it the same as the static
6
by: Peter Michaux | last post by:
Suppose I have implemented a language with garbage collection in C. I have wrapped malloc in my own C function. If malloc returns NULL then I can run the garbage collector and then try malloc...
1
by: Daniel Brower | last post by:
I found documentation that uses the ^ notation after a type name. What does that notation mean? Daniel
1
by: Monica Pnade | last post by:
what does /^/ mean in perl?
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.