Function in C
->Watch this for FUN - Funny job interview
Are you getting bored with online lectures?
->Watch this - When online lectures are boring
Function in C is a very important topic in C. The library in C has many in-built functions like printf, scanf, etc.
Every C program has at least one main function where the code starts executing.
The main function is declared using int main().
Now, we'll be going to see various types of function declaration, their return types, etc.
There are three main things for executing a function in C programming language which are its declaration, its calling, and its execution.
The return type of function includes primitive and derived data types. For data types, refer to this.
Function declaration:
There are two ways where you can declare/call a function.
Way 1:
Declaring outside the main, globally,
int(return type) fun(data type of arguments);
For example,
void fun(int, char); // Function declarationint main()
{
int a=5;
char b='d';
fun(a,b); // Function calling
return 0;
}
void fun(int a,char b)
{
printf("%d\n%c",a,b); // Function execution
}
However only this,
int main()
{
int a=5;
char b='d';
fun(a,b); // Function calling
return 0;}
void fun(int a,char b)
{
printf("%d\n%c",a,b); // Function execution
}
is wrong.
Way 2:
Calling it inside the void main/int main function, but for executing this function, you have to execute it before the function in which you are calling the latter,
void fun(int a, int b)
{
printf("%d\n",a+b); // Execution is possible only if it is written before the function in which it is called
}
int main()
{
int a=3,b=9;
fun(a,b); // Calling the function "fun"
return 0;}
In the above code, you don't have to declare the function "fun" as it is present before the function in which it is called.
->Watch this for FUN - Funny job interview
Are you getting bored with online lectures?
->Watch this - When online lectures are boring
<><><><><><><>
<><><><><><><>
Online learning is an educational mode allowing students to take part in different courses and programs using the internet. In online tuition, students don't need to waste their time going to the lecture halls or classrooms, rather they can decide to learn whatever from any part of the world. For online tuitions you can call - +91-9654271931.
ReplyDelete