Click here to Skip to main content
14,975,416 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
void add_assign3(int *j) {*j = *j + 3; }


why we dont write return *j inside the function ?

What I have tried:

...............................................................
Posted
Updated 27-May-21 22:06pm
Comments
jeron1 27-May-21 17:05pm
   
Because void is the return type, in other words nothing.

1 solution

void add_assign3(int *j) 
{
  *j = *j + 3; 
}

It's a method that has a return type defined as void.

You don't need to provide a return statement in such case. Alternate, you can do:
void add_assign3(int *j) 
{ 
  *j = *j + 3; 
  return;
}

If you want to pass back any value then you would return anything specific and accordingly setup the return type of your method.

Read for more details: Return from void functions in C++[^]
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900