top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What is the difference between void And int function?

+1 vote
536 views
What is the difference between void And int function?
posted Dec 20, 2013 by Jagan Mishra

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

3 Answers

+2 votes

Void returns nothing, int returns something (an int)

answer Dec 20, 2013 by Garima Jain
+1 vote
void fun1(int i)
{
    return i;
}
void fun2(int i)
{
    return;
}

25 => printf("\n    %d   \n",fun1(i));
26 => printf("\n    %d   \n",fun2(i));

return.c: In function âfun1â:
return.c:6: warning: âreturnâ with a value, in function returning void
return.c: In function âmainâ:
return.c:25: error: invalid use of void expression
return.c:26: error: invalid use of void expression

===========================================
int fun4(int i)
{
    return ;
}
int main()
{
    int i = 0;
    for (i = 0; i<5; i++)
    {
        printf("\n    %d   \n",fun4(i));
    }
    return 0;
}
./a.out

    0
    1
    2
    3
    4
===============================================
answer Dec 21, 2013 by Vikas Upadhyay
0 votes

Actually, it is the return type of function, void returns no value whereas an int returns a value called an int (integer)

answer Dec 22, 2013 by Luv Kumar
Similar Questions
+2 votes

Many a times in C we get these two type of main function one had void as parameter one has none. Now the question is what is the difference between these two?

+2 votes

If I correct , by default main () function has integer return type.
I want to know what happens in the system internally when its return type gets changed from integer to void ?

+1 vote

Can someone help me with the example when to use normal function calling and when pointer function calling. What was the reason for introducing pointer function calling in C?

...