Protec Computer Academy (An ISO 9001:2015 Certified Institute, Powered by E-Max Education, Branch Code EMAX/EK-80503, Registered by government of India.) is a best IT training center in Siwan with 100% Job placement assistance. Where you can learn Programming, WebDesigning, Hardware|Networking, Blogging, WordPress, Digitial marketing, English Speaking, And many more...| All certificates are valid in Government Jobs as well as in Private Companies. *** At Tara Market, Beside Vishal Mega Mart - Siwan*** +917541905230, Email- ahmad.irshad781@gmail.com *** Follow us on | | @welcome2protec

Monday, November 9, 2020

Properties of a Function in C

welcome2protec- Properties of a Function: Return type, Function name, Arguments OR Parameters and Body of the Function.

Properties of a function | welcome2protec


In previous, we learned about function in C. A function is a group of statements (Block or Piece of code) wrapped with curly braces ({}) that together perform a specific task is called function. In this tutorial, we will learn properties of a function.


Properties of a Function:

Every C program consist of the following properties as you can see in the below diagram.

Properties of a function | welcome2protec
Properties of a function in C

Above diagram is a example of definition of a function, to use this function we need to call it by passing values as an arguments with the function name. for now you don't worry about it, In the next tutorial we will learn how to create, and how to call a user defined function?


Return Type (OR you can say result type):

It is a type of data which is returned by the function after the function is being called and executed. Return type can be of any data type such as int, char, float, double, void etc. The return type depends on the value to be returned from the function.

Note: The return statements terminates the execution of a function and returns control to the calling function.

Let's see the below examples:

Example 1: Function returning int type value

int get() {
    return 10;  //function returning int type value
}

Here, function is returning integer value. So, the return type of this function should be int data type.


Example 2: Function returning float type value

float get() {
  /*Returning float type value. So return type should be float data type */
  return 10.5;  
}

Example 3: Function returning void type value

void protec() {
  printf("Free online IT tutorial site."); // No returned value. 
}

Now you need to call these functions to get the value. We will learn in the next tutorial, how to create a user defined function and how to call it to get the value.

In C language, when void is used as a function return type as you can see in the above example: "void protec()", That means it indicates that function is not returning anything. When used in a function parameter list like (void), that means void indicates that the function takes no parameters. (Void means nothing).


Is void is a data type? (C Interview)

No it's not a data type. It is just a keyword that means nothing. See the below example to understand it better

For Example:

#include <stdio.h>
 int main()
 {
   int size;
   size = sizeof(void);
   printf("%d", size);
   return 0;
 }

Output

compilation error
/* If will try to find the size of void then compilier will show an error 
 * message "not type allowed" as we cannot use any storage class modifier 
 * with void, since void doesn't reserve any memory space. Hence we cannot 
 * declare any variable as of void type i.e. void num*/
   void num // Compilitation error
  

Function Name:

It can be anything, however it is advised to have a meaningful name for the functions so that it would be easy to understand the purpose of function just by seeing it’s name. For example: sum(); is a function name. See above diagram.


Arguments OR Parameters:

Arguments are nothing but variables declared inside the parenthesis () is called arguments or parameters. For example: sum(int a, int b); where variables a and b are arguments or parameters. These variables are used to pass values from the calling function to the receiving function. You can see in the above diagram.


Declaration statement:

In C language, a delcaration statement describing an identifier, sunch as the name of a variable and it's type. All variables must be declared with a specific data type before assigning a value. For example: int c; as you can see in the above diagram.


Body of the Function:

A function body is a group of statements wrapped with curly braces. For example: code written inside the curly {...} braces is called body of the function. You can see in the above diagram.


Function definition:

A function definition provides the actual body of the function.(function definition is not part of the function Prototype).














Protec Computer Academy (An ISO 9001:2015 Certified Institute, Powered by E-Max Education, Branch Code EMAX/EK-80503, Registered by government of India.) is a best IT training center in Siwan with 100% Job placement assistance. Where you can learn Programming, WebDesigning, Hardware|Networking, Blogging, WordPress, Digitial marketing, English Speaking, And many more...| All certificates are valid in Government Jobs as well as in Private Companies. *** At Tara Market, Beside Vishal Mega Mart - Siwan*** +966532621401, Email- ahmad.irshad781@gmail.com *** Follow us on | | @welcome2protec

Help others by sharing this page.

Ahmad Irshad

Author & Editor

I love blogging, teaching, learning computer science and sharing it to others. I've written and develped this site so that students may learn computer science related tutorials eaisly. MCA / MCITP

0 Comments:

Post a Comment

Please don't enter any spam link in the comment box.


Protec Computer Academy (An ISO 9001:2015 Certified Institute, Powered by E-Max Education, Branch Code EMAX/EK-80503, Registered by government of India.) is a best IT training center in Siwan with 100% Job placement assistance. Where you can learn Programming, WebDesigning, Hardware|Networking, Blogging, WordPress, Digitial marketing, English Speaking, And many more...| All certificates are valid in Government Jobs as well as in Private Companies. *** At Tara Market, Beside Vishal Mega Mart - Siwan*** +966532621401, Email- ahmad.irshad781@gmail.com *** Follow us on | | @welcome2protec
Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec Protec
Contact Us