Clouds
Home
Tutorial of C language
Computer Language
Introduction to C
Programming in C
Structure of C program
Variable in C
Datatypes in C
Token in C
Operator in C
Precedence of C Operator
Assignment Operator in C
Logical Operator in C
Bitwise Operator in C
Ternary Operator in C
C Input Output
Pointers in C
Storage Classes of C
Control Structure of C
C Decision Making Statement
C Looping Statement
C Jumping Statement
C Function
Function Call By Value
Function Call By Reference
C Input Output Function
C Structure
Array in C
Union in C

Function

  • A function is a module or block of program code which deals with a particular task. Making functions is a way of isolating one block of code from other independent blocks of code.
  • Function are name block that can accept argument from its caller and can return a value to its caller and can be executed with a call to function.

    Declaration and Definition

  • When a function is defined at any place in the program then it is called function definition. At the time of definition of a function actual logic is implemented with-in the function.
  • A function declaration does not have any body and they just have their interfaces.
  • A function declaration is usually declared at the top of a C source file, or in a separate header file.

    There are two types of Function

  • User defined Function
  • Pre-defined Function

    User Defined Function

    Example1:-

    				#include<stdio.h>
    				#include<conio.h>
    				starline()
    				{
    				 	int i;
    				 	for(i=0;i<60;i++)
    				 	{
    				  		printf("-");
    				 	}
    				}
    
    				void  main()
    				{
    				 	clrscr();
    				 	starline();
    				 	printf("\nRoll No.\tName of Student\t\tAddress\n");
    				 	starline();
    				 	printf("\n101\t\Ram Kumar\t\tJNU\n");
    				 	printf("\n102\t\Ram Kumar\t\tJNU\n");
    				 	printf("\n103\t\Ram Kumar\t\tJNU\n");
    				 	printf("\n104\t\Ram Kumar\t\tJNU\n");
    				 	printf("\n105\t\Ram Kumar\t\tJNU\n");
    				 	printf("\n106\t\Ram Kumar\t\tJNU\n");
    				 	starline();
    				 	getch();
    				}
    				

    Example:-

    				#include<stdio.h>
    				#include<conio.h>
    				fun()
    				{
    				 	int n=1000;
    				 	printf("%d",n);
    				}
    				void  main()
    				{
    					int m=100;
    				 	clrscr();
    				 	printf("%d\n",m);
    				 	fun();
    				 	getch();
    				}
    				

    Example2:-

    				#include<stdio.h>
    				#include<conio.h>
    				void  main()
    				{
    				 	int m=100;
    				 	clrscr();
    				 	printf("%d\n",m);
    				 	fun();
    				 	getch();
    				}
    				fun()
    				{
    				 	int n=1000;
    				 	printf("%d",n);
    				}
    				

    Example3:-

    				#include<stdio.h>
    				#include<conio.h>
    				fun()
    				{
    				 	int n=1000;
    				 	printf("%d\n",n);
    				}
    				void main()
    				{
    				 	int m=100;
    				 	clrscr();
    				 	fun();
    				 	printf("%d\n",m);
    				 	getch();
    				}
    				

    Example 4:-

    				#include<stdio.h>
    				#include<conio.h>
    				fun1()
    				{
    				 	int n=10;
    				 	printf("%d\n",n);
    				}
    				fun2()
    				{
    				 	int x=1000;
    				 	printf("%d\n",x);
    				}
    				void main()
    				{
    				 	int m=100;
    				 	clrscr();
    				 	fun1();
    				 	printf("%d\n",m);
    				 	fun2();
    				 	getch();
    				}
    				

    Example 5:-

    				#include<stdio.h>
    				#include<conio.h>
    				void fun1()
    				{
    				 	int a=100;
    				 	printf("%d\n",a);
    				 	void fun2();
    				}
    				void fun2()
    				{
    				 	int b=1000;
    				 	printf("%d\n",b);
    				 	void fun3();
    				}
    				void fun3()
    				{
    				 	int c=10000;
    				 	printf("%d\n",c);
    				}
    				void  main()
    				{
    				 	int d=10;
    				 	clrscr();
    				 	printf("%d\n",d);
    				 	fun1();
    				 	fun2();
    				 	fun3();
    				 	getch();
    				}
    				
    On the basis of call to function
  • Call - by - Value
  • Call - by - Reference
    Function Call By Value >>
    Function Call By Reference >>
    C Input Output Function >>
    C Structure >>
    Array in C >>


    Home Clouds