i'm so confused......when should or must i use void or non void function. and another question one star * and double star **
how t use it ............Thank you very much
Printable View
i'm so confused......when should or must i use void or non void function. and another question one star * and double star **
how t use it ............Thank you very much
You should use void function, when you don't want to return "anything" from that function.
About your second question 'one star or two':
One 'star' means a Pointer, he points to a place on the memory.
Two 'stars' means a Pointer that points to another pointer.
if you be more specific on your question, we can help you more.
i mean sometimes you still want to use or update the value in non void function but u dont have to return it so this makes me confuse
The function should generally be void if you're never going to want it to return a value. This does not stop the function from working with variables or other program information by way of pointers etc.
What value?
A value passed in?
An example of a function that returns void.
Code:#include <stdio.h>
void DumpInt(int);
int main()
{
int j = 10;
DumpInt(j);
printf ("But in main its %d\n", j);
return 0;
}
void DumpInt(int i)
{
printf ("Your number is %d\n", i);
i += 10;
printf ("Your number is now %d\n", i);
}
>>when should or must i use void or non void function.
You use void when all you want is the side effect
As opposed to wanting a direct changeCode:void display(int num)
{
printf("The number is %d\n", num);
}
Code:int add(int a, int b)
{
return a + b;
}