- #1
kthouz
- 193
- 0
What is the effect of putting void before main function i mean?
void main()
{
}
void main(void)
{
}
void main()
{
}
void main(void)
{
}
A function in C language is a block of code that performs a specific task. It can be called multiple times from different parts of the program, making it a reusable component.
To declare a function in C language, you need to specify its return type, name, and parameters (if any). For example:
int sum(int num1, int num2);
This declares a function named "sum" that takes two integer parameters and returns an integer value.
In call by value, the function receives a copy of the argument passed to it, while in call by reference, the function receives the address of the argument. This means that any changes made to the parameter inside the function will affect the original argument in call by reference, but not in call by value.
To return a value from a function in C language, you need to use the return statement. For example:
int sum(int num1, int num2) {
return num1 + num2;
}
This function will return the sum of the two parameters.
Recursion in C language is the process of a function calling itself. It is useful when solving problems that can be broken down into smaller, similar subproblems. However, it is important to have a base case that stops the recursive calls, otherwise the function will continue to call itself indefinitely.