bing
Flat 10% & upto 50% off + Free additional Courses. Hurry up!

C Functions

 

Function is the collection of statements which is used to perform some specific task. It provides code reusability and code optimization.

Syntax to declare function in C

return_type function_name(data_type parameter...){

//code

}
  • return_type indicates the data type of the return value.
  • function_name specify the name of the functions.
  • Parameter are the values which is passed in the function.

A function declaration informs the compiler about a function name and how to call the function. The actual body of the function can be defined separately.

Syntax to call function in C

variable=function_name(arguments...);

Example 

#include <stdio.h>

#include <conio.h>

void sum(int a, int b);

void main()

{

clrscr();

int a, b, c;

c= sum(2,3);

getch();

}

void sum(int a, int b)

{

c = a+b;

printf(“%d”,c)

}

Output

5

There are 2 ways of calling function that are

  1. Call by value
  2. Call by reference

 

1. Call by value

This method copies the actual value of an argument into the formal parameter of the function. In this case, changes made to the parameter inside the function have no effect on the argument.

2. Call by reference

This method copies the address of an argument into the formal parameter. Inside the function, the address is used to access the actual argument used in the call. This means that changes made to the parameter affect the argument.

 

Recursion

When function is called within the same function, it is known as recursion in C. A function that calls itself, and doesn’t perform any task after function call, is known as tail recursion.

Syntax

recursionfunction()

{

recursionfunction();//calling self function

}

"0 Responses on C Functions"

Training in Cities

Bangalore, Hyderabad, Chennai, Delhi, Kolkata, UK, London, Chicago, San Francisco, Dallas, Washington, New York, Orlando, Boston

100% Secure Payments. All major credit & debit cards accepted Or Pay by Paypal.

top

Sales Offer

  • To avail this offer, enroll before 05th December 2016.
  • This offer cannot be combined with any other offer.
  • This offer is valid on selected courses only.
  • Please use coupon codes mentioned below to avail the offer
offer-june

Sign Up or Login to view the Free C Functions.