ArtsAutosBooksBusinessEducationEntertainmentFamilyFashionFoodGamesGenderHealthHolidaysHomeHubPagesPersonal FinancePetsPoliticsReligionSportsTechnologyTravel
  • »
  • Technology»
  • Computers & Software

Function Call by Name in C Programming Language

Updated on June 18, 2012

C Language

A function in C language is a block of code that performs a specific task. It has a name and it is reusable i.e. it can be executed from as many different parts in a C Program as required. It also optionally returns a value to the calling program

So function in a C program has some properties discussed below.

  • Every function has a unique name. This name is used to call function from “main()” function. A function can be called from within another function.

  • A function is independent and it can perform its task without intervention from or interfering with other parts of the program.

  • A function performs a specific task. A task is a distinct job that your program must perform as a part of its overall operation, such as adding two or more integer, sorting an array into numerical order, or calculating a cube root etc.

  • A function returns a value to the calling program. This is optional and depends upon the task your function is going to accomplish. Suppose you want to just show few lines through function then it is not necessary to return a value. But if you are calculating area of rectangle and wanted to use result somewhere in program then you have to send back (return) value to the calling function.

C language is collection of various library functions. If you have written a program in C then it is evident that you have used C’s inbuilt functions. Printf, scanf, clrscr etc. all are C’s inbuilt functions. You cannot imagine a C program without function.

Structure of a Function

A general form of a C function looks like this:

<return type> FunctionName (Argument1, Argument2, Argument3……)

An example of function.

int sum (int x, int y)
int result;
result = x + y;
return (result);

Function Prototype and Function Definition in C Programming

Function prototype is very simple concept but the word (prototype) we use to call it makes it difficult to new C programmer to understand. In simple word, function prototype tells compiler that we are going to use a function which will have given name, return type and parameters. It’s that simple.

Function definition on the other hand is just writing logic of any function. For example you have one function prototype in C program for adding two integer numbers (i.e. int add(int, int)) but along with prototype you also have to write logic how that function will behave (respect to above prototype; how you will utilize those two passed integer value and how you will return value) when you will call that function.

Let’s take look at example for better and clear understanding:

Function Prototype and Function Definition Example


void myFunction();
int add(int, int);

void main()



void myFunction()
	printf("This is inside function :D");

int add(int a, int b)
	return a+b;


Now we have a simple C program to demonstrate function prototype and function definition concept. We will start from line no. 4 & 5. In these two lines we have function prototype, line no. 4 has a simple function prototype which doesn’t have parameters or return type. It’s very simple to declare a prototype, see line no. 17 & 4, both line are same except prototype requires semicolon (;) at the end. Code block (line no. 17-20) is function definition for our first function prototype (i.e. line no. 4). In this block we are defining behavior of that function and in my code it’s just printing a simple message for demonstration.

Similarly we have second function prototype (line no. 5) and it has parameters and return type. Code block (line no. 22 – 25) is definition of above function prototype. One important point for function prototype having parameters; in prototype, variable name for parameters is optional (see line no. 5). There is no variable name for int parameters, its (int, int). But in that prototype’s function definition you must provide parameter variable name (see line no. 22). We have (int a, int b) parameter name.

One more important thing, if you writing function definition above main() function then you don’t need to write prototype of that function. But it’s a good practice to keep all the functions below main() function.

Advantages of using functions:

There are many advantages in using functions in a program they are:

  1. It makes possible top down modular programming. In this style of programming, the high level logic of the overall problem is solved first while the details of each lower level functions is addressed later.
  2. The length of the source program can be reduced by using functions at appropriate places.
  3. It becomes uncomplicated to locate and separate a faulty function for further study.
  4. A function may be used later by many other programs this means that a c programmer can use function written by others, instead of starting over from scratch.
  5. A function can be used to keep away from rewriting the same block of codes which we are going use two or more locations in a program. This is especially useful if the code involved is long or complicated.

Types of functions:

A function may belong to any one of the following categories:

  1. Functions with no arguments and no return values.
  2. Functions with arguments and no return values.
  3. Functions with arguments and return values.
  4. Functions that return multiple values.
  5. Functions with no arguments and return values.

Note : You can find details about different types of function in C language, click here read it now.

Example of function calling in C

void add(int x,int y)
int result;
result = x+y;
printf("Sum of %d and %d is %d.\n\n",x,y,result);
void main()

Program Output

Output of above program.
Output of above program.


Before I explain, let me give you an overview of above c program code. This is a very simple program which has only function named “add()” . Calling this C function from “main()” is very simple. This “add()” function takes two values as arguments, adds those two values and prints the result.

Line 3-8 is a function block of the program. Line no. 3 is the header of function, void is return type of function, add is function name and (int x, int y) are variable which can hold integer values to x and y respectively. When we call function, line no. “12, 13, 14”, we need to send two integer values as its argument. Then these two values get stored in variable x and y of line no. 3. Now we have two values to perform addition; in line no. 5 there is an integer declaration named “result”. This integer will store the sum of x and y (please see line no. 6). Line no. 7 simply prints the result with C’s inbuilt function “printf”.

Now imagine the same program without using function. We have called “add()” function three times, to get the same output without using function we have to write Line no. 6 & 7 three time. If you want to add more value later in the program then again you have to type those two lines. Above example is a small and simple program so it does not appear great to use function. But assume a function consist 20 – 30 or more lines then it would not be wise to write same block of code wherever we need them. In such cases functions come handy, declare once, use wherever you want.

Share your opinion with me

Did this tutorial helped you to learn function in C language?

See results


    0 of 8192 characters used
    Post Comment

    • profile image

      DoveFreexrolo 2 years ago

      Helpful information. Fortunate me I found your website unintentionally, and I am surprised why this twist of fate didn took place earlier! I bookmarked it.

    • profile image

      nayanshill@2016 2 years ago

      all c++ 2016

    • profile image

      Usha K S 3 years ago

      I Cleared my doubts after view'd ur site....

      THANK U...

    • profile image

      alpa alok 4 years ago


    • profile image

      Nu Dombkowski 4 years ago

      [quote]8192 characters left.[/quote]

      Good write ups, With thanks..

      Nicely put, Thanks a lot.

    • profile image

      Rono Dominic 5 years ago

      What is the difference between calling a function by value and by reference?

    • profile image

      pihu 5 years ago

      thanks, it help me to understand function . but give more example for better understanding

    • profile image

      aashi 5 years ago


    • profile image

      mah 5 years ago

      what is the differece between formal and actual arguments?

    • profile image

      faisal 5 years ago

      yar main ny jitny b functions waly programs try kiye hain koi b nai chala hi... sir your program is also dont working so give me some more examples. with full syntex. thanx

    • profile image

      fredfmah 5 years ago

      Dear Raj, many thanks for a clear exposition of each theme.

      I didn't see an example for something similar to what I am trying to code.

      I am using a Pic 18F2550 and the C18 c0mpiler.

      The program itself is very simple in structure.


      NTC thermistor -- 18F2550 -- LCD 44780


      Yes a thermometer.

      You explained some very important things to me. I program quite well in Pic Assembler but you helped me see.

      1. What in C is named as a function, It is named as a subroutine in assembler

      2. The assembler program usually has a MAIN which basically "call" a set of subroutines.

      You showed me the Call word is not need in C, naming the subroutine is sufficient

      3. Just one little problem .

      In the above thermometer example, before you can send data to the LCD, you need to Initiate with a series of set up commands.

      This is a ONE TIME block of code.

      Then after that the following functions are


      sequence then is

      0. Initiate

      1. Read NTC resistance do 10bit voltage to Resistance conversion..

      2.Do maths to convert the resistance to temperature

      3. Send temperature to the LCD

      4. Go back to 1. for the next temperature reading.

      I'm thinking this is a loop , an infinite while(1) loop only broken by an out of range voltage.

      Then print resistance error.

      I'll keep on reading your C seminar to see if you think something like this could be of general interest.

      My best wishes


      Madrid, Spain

    • profile image

      rocky 5 years ago

      thank you so much...

    • profile image

      rainbow sky 5 years ago

      Can help me do this?

      Write a complete user friendly menu driven C program to perform Matrix operations such as Addition, Subtraction, Multiplication and Transpose according to the user’s choice.


    • profile image

      Megha 5 years ago

      Dear sir,want to know about data abstraction in c++.sir I cannot understand it .I think that data abstraction also occur in c language also sir please helpme and please tell me your book of c++ link

    • profile image

      bhavna 5 years ago

      sir i ask

    • profile image

      Rupesh Kumar 6 years ago

      its verry-verry helpful for me.....

    • profile image

      vijay 6 years ago

      good explanation

    • rajkishor09 profile image

      RAJKISHOR SAHU 6 years ago from Bangalore, Karnataka, INDIA

      If you want you can check types of function tutorials also....

    • profile image

      himanshu gehani 6 years ago

      that's call function definition.Very good function describe and give the examples.

    • profile image

      abdul salam 6 years ago

      it's very easy and helpful solution of function . i like it

      it's easy example for explain. sorry ,but i am weak in c.

      i hope you can helped me.

      please give me 'c' notes.

      thank you.

    • profile image

      aiyein 6 years ago

      can you help me to do this?

      i cant get the output, but there's no mistakes in my coding.

      'write a program that ask the user to enter a temperature reading in centigrade and then prints the equivalent Fahrenheit value. It then ask the user to enter a Fahrenheit value and prints out the equivalent centigrade value. Run the program several times. Be sure to include at least one negative temperature reading in your test cases. Provide separate functions as needed by your design.Your main function should have only function calls. The input, Fahrenheit=100, Celsius=36.9 '

      Hope you can help me.. thank you!

    • profile image

      indresh bind 6 years ago

      I love c language thanks to chetan vyas sir. mai kuch mahine pahale c me kuch bhi nahi janta tha aur aaj mai program ache se kar leta hu jiska pura shrey chetan sir ko jata hai jisne itni mehanat ke sath mujhe padaya aur mujhe guide kiya thanks sir.

    • profile image

      hera 6 years ago

      a program that will take total marks of 3 frndz koli,joli, moli

      grading scheme: more than 89=A+,80 to 89=A,70 to 79=B+,

      60 to 69=B,50 to 59 =C,less than 50=F.

      kathy got the higest .

      sample input:75,95,85

      sample out put:joli got the higest number.

    • profile image

      hera 6 years ago

      its so nice

    • profile image

      heena 6 years ago

      i want to print a rectangle using functions and for loop in c...any help please

    • profile image

      piusraiser 6 years ago

      can you help me to solve this program

      Print following pattern using a C program.take the string as input from the user .write a genric program to acceptt string of any length...

      Example pattern

      If the user input nepal than the output should be as follow






    • profile image

      hussainbutt 6 years ago

      Thank you this is really very helpful for me. Thanks again.

    • profile image

      daman bakhariya 6 years ago

      very good who have posted this

    • profile image

      bipin stha 6 years ago

      differentiate between call by value and call by referance while calling a function

    • profile image

      rogelio 6 years ago

      hi!sir could you please give me an idea to make this program!!

      1. Write a program that determines whether a positive integer is a prime number. A prime number is a number that can only be evenly divided by 1 and itself. The program should contain the function,isPrime, and returns 1 if the integer is a prime number and return 0 if otherwise.

    • profile image

      shalaka gharade 6 years ago

      thanks dude

    • profile image

      Rahul Rawat 6 years ago

      thanks sir it was amazing.

    • profile image

      sandeep 6 years ago

      its very helpful for me thanks

    • profile image

      ankita gupta 6 years ago

      it is very useful thanx to give us brief knowledge

    • profile image

      Banker 6 years ago

      code for the print the longest word written in a line using udf...plzz reply fast...

    • profile image

      TANUJA 6 years ago


    • profile image

      madura bharathi 6 years ago

      no comment

    • profile image

      vineela 6 years ago

      we can know more new things in c-programs

    • rajkishor09 profile image

      RAJKISHOR SAHU 6 years ago from Bangalore, Karnataka, INDIA

    • profile image

      shivani 6 years ago

      m asking 1 que.....

      what is different betbeen call by reference and call by result value

    • rajkishor09 profile image

      RAJKISHOR SAHU 6 years ago from Bangalore, Karnataka, INDIA

      @Pravin : Thanks for your nice comments, it really gives motivation to write more tutorials when friends like you appreciate. By the way we can become friends on facebook, in my profile I have provided link. Take care and happy learning.............

    • profile image

      now refreshed pravin 6 years ago

      itzzzz amazing raj..i dint really knew anything abt functions.the way u arrange things with numbering of each line and their link to other line is simply incredible.if i become a gr8 s/w engg,i wud surely say u were the man behind me..i wud be pumped if i cud meet u..,i live in hosur which is quite near to urs..giv ur to this

    • rajkishor09 profile image

      RAJKISHOR SAHU 6 years ago from Bangalore, Karnataka, INDIA

      @Biplab: You can find that information here

    • profile image

      biplab 6 years ago

      Types of functions:

      A function may belong to any one of the following categories:

      Functions with no arguments and no return values.

      Functions with arguments and no return values.

      Functions with arguments and return values.

      Functions that return multiple values.

      Functions with no arguments and return values.plz explain it

    • profile image

      sunil nirmalkar 6 years ago

      sir plz explaun the nots:- 1)introduction to programming 2)Algorithms for problem solving 3)introduction to 'c'lang 4)condition statements and loops 5)arrays 6)function 7)strctures and unions 8)structures and unions 9)pointers 10)self Refential structures and linked lists 11) file processing...plz plz sir i wat my e-mail id :-

    • profile image

      abc 6 years ago

      plz sir explain need of user defined function

    • profile image

      Tanu sharma 6 years ago

      sir plz will u explaun the program of recurrsion plz sir i cnt get tht program

    • profile image

      trishul 6 years ago

      please explain the program, how the execution will done:

      int main()


      int c=printf("hello");

      return 0;



    • profile image

      Rajesh 6 years ago

      hi, mr.raj

      am asking: 1. what is prototype?

      can explain other way plz.

      2. call by value,call by reference ?

    • profile image

      Nancy 6 years ago

      thanks a lot.

    • profile image

      priya 6 years ago


      its very useful...

    • profile image

      jessy 6 years ago

      Hi,some doubts..

      why do u write getch() in void main()?

      How do u realize whether your function should return a value?


    • rajkishor09 profile image

      RAJKISHOR SAHU 6 years ago from Bangalore, Karnataka, INDIA

      @Kishan Patel : factorial program is already there, visit

    • profile image

      kishan patel 6 years ago

      hiiiiii sir,you are awesome but can you give me a program to find the factorial of a number,please post it fast.................

    • profile image

      kishan patel 6 years ago

      hiiiiiiiiiiiiiiii!!!!!it's really good,but I am a student of 8 grade,so i want extra explanation,will you help by online chat.AS i am intrested in this when you are online,please tell me

    • profile image

      Asif Raza 6 years ago

      bundle of thanks ,i have learnt much of functions

    • profile image

      aravind 6 years ago

      how to pass the characters using function..(without using pointers)

    • profile image

      A/razak haji 6 years ago

      My problems in c function are solved now

    • profile image

      dinu(baby) 6 years ago

      thanx, it's good using function.

    • profile image

      Hi.. mukesh kumar from varanasi 6 years ago

      It is a good progrram using function.

    • profile image

      M Junaid Awan 6 years ago

      good job man....

    • profile image

      soham 6 years ago

      thnx man...saved my ass before my semester.! :)

    • profile image

      nag 6 years ago

      thank you

    • profile image

      Ron 6 years ago

      thnks for info

    • profile image

      nek yadav 6 years ago

      thanx dude u are a great teacher. my whole problems are solved now in function.

    • profile image 6 years ago

      what are the type conversions ?explain with the help of an example?

    • profile image

      renuka 6 years ago

      sir please explain deeply about function prototype and finction defination

    • profile image

      rohit 6 years ago

      sir plz give me details fuction in c for collage seminar

    • profile image

      aruna 6 years ago


      5 5

      5 5 5

      plz send me d 'c' code for the above problem

    • profile image

      ankur 6 years ago

      what is the program of multiplication in function

    • profile image

      nk 6 years ago


    • profile image

      maneesh dwivedi 6 years ago

      thank u sir i am very happy to get such help by ur programs

    • profile image

      Balaji Naidu 6 years ago

      will u please post the program explaining using function inside a function.......which explains clearly....pls do favour....

    • profile image

      gaurav nigam 6 years ago


    • profile image

      dip 6 years ago

      i'm realy thankful to u.

    • profile image

      akasha 6 years ago

      dear sir!

      i m so much happy for your nice procedure in c.thanks ......

    • profile image

      shah 6 years ago

      hi sir

      i really understand from this description. so thnx dear

    • profile image

      EMAN 6 years ago

      Thanx for providing guideeness

    • profile image

      elanr 6 years ago

      Can we pass "result" as interger as argument inside the add function, without passing separately?


      void (int x, int y, int result)

    • profile image

      ilia 6 years ago

      This is so clear and easy to understand.Thanks a lot.

    • profile image

      barkha 6 years ago

      pls explain c progrmming ??

    • profile image

      raju karri 6 years ago

      the programm was gud and its a nice procedure

    • profile image

      diksha 6 years ago

      sir can you please give some more examples of functions that will make it more understandable???

    • profile image

      paras rajput 6 years ago

      nice it solve my problem

    • profile image

      sandy 6 years ago



    • profile image

      m.ramadivya 6 years ago

      good for reading it

    • profile image

      sanuj +91-9809600720 6 years ago

      i want to know both Advantages and Disadvantages of C functions

    • profile image

      jay 6 years ago

      how to develop the program swap the no without using variable?

    • profile image

      pramod singh 6 years ago

      i want to know full discription abaut functions in c

    • profile image

      kutubuddin azad 6 years ago

      in my exam, syllabus for coputer paper is functions of c, but my pages are lost of thus lesson and i was finding this lesson, so, i got it in internt, i am very happy today

    • profile image

      mahmud 6 years ago


    • profile image

      parminder singh 6 years ago

      it is more efficient for knowledge

    • profile image

      shruthi 6 years ago

      thanx for this help

    • rajkishor09 profile image

      RAJKISHOR SAHU 6 years ago from Bangalore, Karnataka, INDIA

      @Chaithanya : logic looks like (any no.) * 8 + last digit of that (any no.)

      1*8+1=9, here last digit is 1

      12*8+2=98, here last digit is 2

    • profile image

      Yogesh Ghariya 6 years ago

      thanx a lot!!!

    • profile image

      Chaithanya 6 years ago


      i need a program for a calculation as follows







      what's the logic please help me

    • profile image

      nana 6 years ago

      pls how solve the infix to prefix & prefix evaluation

    • profile image

      sushmita gupta 6 years ago

      Hello Sir,

      I have a tc through which i execute all my c & c++ pgm.

      I want to run Window base pgm through my tc compiler but it has not window.h header file.

      How can i add that header file into my tc.

      Please sir reply me.

    • profile image

      rambo 6 years ago

      a good example

    • profile image

      venkatesan 6 years ago

      hello brother is this enough to study c language?


    This website uses cookies

    As a user in the EEA, your approval is needed on a few things. To provide a better website experience, uses cookies (and other similar technologies) and may collect, process, and share personal data. Please choose which areas of our service you consent to our doing so.

    For more information on managing or withdrawing consents and how we handle data, visit our Privacy Policy at: ""

    Show Details
    HubPages Device IDThis is used to identify particular browsers or devices when the access the service, and is used for security reasons.
    LoginThis is necessary to sign in to the HubPages Service.
    Google RecaptchaThis is used to prevent bots and spam. (Privacy Policy)
    AkismetThis is used to detect comment spam. (Privacy Policy)
    HubPages Google AnalyticsThis is used to provide data on traffic to our website, all personally identifyable data is anonymized. (Privacy Policy)
    HubPages Traffic PixelThis is used to collect data on traffic to articles and other pages on our site. Unless you are signed in to a HubPages account, all personally identifiable information is anonymized.
    Amazon Web ServicesThis is a cloud services platform that we used to host our service. (Privacy Policy)
    CloudflareThis is a cloud CDN service that we use to efficiently deliver files required for our service to operate such as javascript, cascading style sheets, images, and videos. (Privacy Policy)
    Google Hosted LibrariesJavascript software libraries such as jQuery are loaded at endpoints on the or domains, for performance and efficiency reasons. (Privacy Policy)
    Google Custom SearchThis is feature allows you to search the site. (Privacy Policy)
    Google MapsSome articles have Google Maps embedded in them. (Privacy Policy)
    Google ChartsThis is used to display charts and graphs on articles and the author center. (Privacy Policy)
    Google AdSense Host APIThis service allows you to sign up for or associate a Google AdSense account with HubPages, so that you can earn money from ads on your articles. No data is shared unless you engage with this feature. (Privacy Policy)
    Google YouTubeSome articles have YouTube videos embedded in them. (Privacy Policy)
    VimeoSome articles have Vimeo videos embedded in them. (Privacy Policy)
    PaypalThis is used for a registered author who enrolls in the HubPages Earnings program and requests to be paid via PayPal. No data is shared with Paypal unless you engage with this feature. (Privacy Policy)
    Facebook LoginYou can use this to streamline signing up for, or signing in to your Hubpages account. No data is shared with Facebook unless you engage with this feature. (Privacy Policy)
    MavenThis supports the Maven widget and search functionality. (Privacy Policy)
    Google AdSenseThis is an ad network. (Privacy Policy)
    Google DoubleClickGoogle provides ad serving technology and runs an ad network. (Privacy Policy)
    Index ExchangeThis is an ad network. (Privacy Policy)
    SovrnThis is an ad network. (Privacy Policy)
    Facebook AdsThis is an ad network. (Privacy Policy)
    Amazon Unified Ad MarketplaceThis is an ad network. (Privacy Policy)
    AppNexusThis is an ad network. (Privacy Policy)
    OpenxThis is an ad network. (Privacy Policy)
    Rubicon ProjectThis is an ad network. (Privacy Policy)
    TripleLiftThis is an ad network. (Privacy Policy)
    Say MediaWe partner with Say Media to deliver ad campaigns on our sites. (Privacy Policy)
    Remarketing PixelsWe may use remarketing pixels from advertising networks such as Google AdWords, Bing Ads, and Facebook in order to advertise the HubPages Service to people that have visited our sites.
    Conversion Tracking PixelsWe may use conversion tracking pixels from advertising networks such as Google AdWords, Bing Ads, and Facebook in order to identify when an advertisement has successfully resulted in the desired action, such as signing up for the HubPages Service or publishing an article on the HubPages Service.
    Author Google AnalyticsThis is used to provide traffic data and reports to the authors of articles on the HubPages Service. (Privacy Policy)
    ComscoreComScore is a media measurement and analytics company providing marketing data and analytics to enterprises, media and advertising agencies, and publishers. Non-consent will result in ComScore only processing obfuscated personal data. (Privacy Policy)
    Amazon Tracking PixelSome articles display amazon products as part of the Amazon Affiliate program, this pixel provides traffic statistics for those products (Privacy Policy)