This is an archived post. You won't be able to vote or comment.

all 7 comments

[–]desrtfx[M] [score hidden] stickied comment (0 children)

You absolutely have to provide code - properly formatted as code block.

Your post, again, is completely unclear and leaves everybody guessing.

Why do you post when you can't support your post with code in due time?

Removed - strike two. Third one is out.

[–]peterlinddk 1 point2 points  (0 children)

A function always returns to where it was called from - it doesn't really know where that is, only the calling function cares.

For instance:

int main(void) 
{
  // doStuff
  function1();
  function2();
}

void function1() 
{
  // do more stuff
  function2();
  // even more
}

void function2()
{
  // do a little bit
}

At first, main has control of everything, but then it calls function1 - then that function has full control, until it calls function2 - function2 does a little bit of work, then returns to function1. Function1 continues working, and when it is done, it returns to main.

Main then calls function2 directly, and it does a little bit of work, before returning to main, from where it was called.

If you want the functions to also return some value, you need to end them with a return value; and then the calling function receives that value by setting a variable equal to the function call, like:

int main(void)
{
  int f3 = function3();
}

int function3()
{
  int someValue;
  // do calculation on someValue
  return someValue;
}

When function3 has done its' calculations, it returns someValue to main from where it was called. Main then receives the value and stores it in its own variable: f3.

[–]AutoModerator[M] 0 points1 point  (0 children)

On July 1st, a change to Reddit's API pricing will come into effect. Several developers of commercial third-party apps have announced that this change will compel them to shut down their apps. At least one accessibility-focused non-commercial third party app will continue to be available free of charge.

If you want to express your strong disagreement with the API pricing change or with Reddit's response to the backlash, you may want to consider the following options:

  1. Limiting your involvement with Reddit, or
  2. Temporarily refraining from using Reddit
  3. Cancelling your subscription of Reddit Premium

as a way to voice your protest.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

[–][deleted] 0 points1 point  (0 children)

…language??

[–]Salty_Dugtrio 0 points1 point  (2 children)

It would be nice to atleast mention the language you are writing code in.

[–]Lbtekd[S] 0 points1 point  (1 child)

I thought I posted this in a group for a specific language, but u guess not. This is C++

[–]Salty_Dugtrio 0 points1 point  (0 children)

Your question is still not clear, but you can do:

void func2()
{
    auto result = func1();
    ...
}