void doSomething(int a)
int doSomething(int a)
A function doesn't have to return something for it to be useful. Most of the time when you want a function to return a value it's so you can work out whether whatever the function was supposed to do was a "success" or "failure".SoSolid said:Again....what is the point of asking c to do something and then not returning a result!?
Durzel said:A function doesn't have to return something for it to be useful. Most of the time when you want a function to return a value it's so you can work out whether whatever the function was supposed to do was a "success" or "failure".
You could have a function, for example, which just increments a counter that is stored globally (I'm over-simplifying the concept of passing variables by reference, etc).. that function doesn't need to return anything to the part of code that calls it.
SoSolid said:I hate c. I am trying to make a program which calculates all the prime numbers up to 1000. I don't understand this void business at all.
rudeboymcc said:don't think i've heard anyone say they hate c. have you programmed in other languageS?
burnsy2023 said:Learn Java, then you'll love C/C++
Burnsy
Surely that wouldn't be returning something? That would be altering a variable passed into the function?pinkaardvark said:Also worth noting that even though something is void(in vb this would be a sub rather than a function) you can still of course return something by setting the value of the arguments if they are reference types.
Welshy said:Surely that wouldn't be returning something? That would be altering a variable passed into the function?