difference between two function

Thread Starter

Parth786

Joined Jun 19, 2017
642
Hi
I have doubt on some term. I am explaining with example
first example
Code:
void main (void)
{
   // function statement //
}
The first term void indicate that the function does not return any value. and second term indicate that function does not send any data in the form of argument

Second example
Code:
int main (void)
{
   // function statement //
return 0;
}
this function return integer 0

Third example
Code:
void wait (void)
{
   // function statement //
}
Q1. when and where do we use specific types of function ?
Q2. what is meaning of function return integer ? does any function return character?
 

WBahn

Joined Mar 31, 2012
30,088
The return type of a function is the type of value that the function returns. It's that simple.

In most implementations, functions are implemented using a stack. The arguments passed to the function are first placed on the stack. Control is then transferred to the function, which can easily access the arguments because they are sitting conveniently on top of the stack. The function does its stuff and the last thing it does before it returns is strip the arguments that were passed to it off the stack and place the return value there. Then control is returned to the caller, who can access the return value because it is sitting on top of the stack.

If a function's return type is void then it just strips the arguments off the stack put doesn't put any return value on it and the calling function knows not to look for any.

If the argument list is void, then the calling function doesn't place any arguments on the stack and the function knows not to look for any.

A function may return a value of any type other than an array or a function (though it can return a pointer to either).
 

Thread Starter

Parth786

Joined Jun 19, 2017
642
Ok this mean functions can be called either with arguments or without arguments in a C program. These functions may or may not return values to the calling function
function With arguments and with return values
Code:
int function( int i )
{
statements;
return i;
}
Parameter :i
Return value : integer
function With arguments and without return values
Code:
void function( int i )
{
statements;
}

can we write function like this
Code:
void function(int i, char a, array[ ], int*pointer)
{
statements;

}
 

WBahn

Joined Mar 31, 2012
30,088
can we write function like this
Code:
void function(int i, char a, array[ ], int*pointer)
{
   statements;
}
No, but almost.

The problem is that your function doesn't know what type of data is in the array. Let's say it is an array of doubles. Then you could write

Code:
void function(int i, char a, double array[ ], int *pointer)
{
   statements;
}
 

Thread Starter

Parth786

Joined Jun 19, 2017
642
Example 1: In this example, variable declare inside bracket
Code:
void function(int variable_name)
{
   statements;
}
Example 2: In this example, variable declare inside Curly bracket
Code:
void function( )
{
  int variable_name
   statements;
}
what is basic difference between two methods? Is there any specific reason ?
 

WBahn

Joined Mar 31, 2012
30,088
In the first case the variable is initialized with a value that is passed into by the caller. In the second case it is simply a local variable.

You REALLY need to take a course or work your way through a text on C programming. There are several free, online courses and tutorials available.
 

Thread Starter

Parth786

Joined Jun 19, 2017
642
In the first case the variable is initialized with a value that is passed into by the caller. In the second case it is simply a local variable.

You REALLY need to take a course or work your way through a text on C programming. There are several free, online courses and tutorials available.
I have downloaded some text books and I am reading those books. while reading this confusen create in my mind. I am trying to solve many example myself but somewhere I don't understand concepts. I always stuck in selection.
 
Top