C - IntroductionC - Hello World ProgramC - Exercise 1C - Basic structure of a C programC - TokensC - Data TypesC - Type ConversionC - Exercise 2C - Character Input Output OperationsC - Input Output operation using scanf and printf functions

Operators

C - Arithmetic OperatorsC - Relational OperatorsC - Logical OperatorsC - Assignment OperatorsC - Increment Decrement OperatorsC - Bitwise Operators

Precedence and Associativity

C - Precedence and AssociativityC - Exercise 3

Conditions

C - If Else decision making statementsC - Switch Case decision making statements

Loop

C - While LoopC - Do While LoopC - For LoopC - Exercise 4

Array

C - ArraysC - Two Dimensional ArraysC - Multi Dimensional ArraysC - Exercise 5

String

C - StringC - Exercise 6C - String Manipulation

Functions

C - FunctionsC - Functions CategoryC - Function Call - Flow of ControlC - RecursionC - Functions and ArraysC - Functions and Strings

Structures

C - StructuresC - Structures and ArraysC - Passing structure to functionC - Function returning structureC - Structure in Structure

Pointers

C - PointersC - Pointers and VariablesC - Pointers and Variables Memory RepresentationC - Pointers Chaining

Pointers and Arrays

C - Pointers and One Dimensional ArrayC - Pointers and Two Dimensional ArrayC - Array of Pointers

Pointers and Strings

C - Pointers and Strings

Pointers and Functions

C - Pointers and Functions - Call by Value and Call by ReferenceC - Function returning pointer

Pointers and Structures

C - Pointers and StructuresC - Pointers and Array of StructuresC - Passing structure pointer to function

Handling Files

C - File Handling - Getting StartedC - File Handling - Read and Write CharactersC - File Handling - Read and Write IntegersC - File Handling - Read and Write multiple dataC - File Handling - Randomly Access Files

Command Line Arguments

C - Command Line Arguments

Dynamic Memory Allocation

C - Dynamic Memory Allocation - Getting StartedC - Dynamic Memory Allocation - malloc functionC - Dynamic Memory Allocation - calloc functionC - Dynamic Memory Allocation - realloc function

C - Functions Category

C Programming

In this tutorial we will learn about category of functions in C programming language.

Function Parameter and Function Argument

A parameter is a variable that we use in a function definition. An argument is the actual data that we pass to the function parameter.

Example:

#include <stdio.h>

//Function declaration
float getArea(float, float);

int main(void) {

  /**
   * We are calling the getArea() function
   * The arguments passed to the function are 10 and 20.
   */
  float area = getArea(10, 20);

  //output
  printf("Area: %f\n", area);

  return 0;
}

/**
 * Function definition
 * Following are the parameters of the given function getArea()
 * length
 * width
 */
float getArea(float length, float width) {
  return length * width;
}

In the above example the function arguments are 10 and 20 whereas, the function parameters are length and width.

So, argument value 10 is stored in the parameter name length and argument value 20 is stored in the parameter name width respectively.

Function categories

We have already learned about functions is the previous tutorial. Now, in this tutorial we will talk about four categories of functions.

  • Function with no argument and no return value
  • Function with no argument but returns a value
  • Function with argument but no return value
  • Function with argument and returns a value

Function with no argument and no return value

To create a function with no argument and no return value we set the parameter list to void and the return type of the function to void.

In the following example we have a function print10() that takes no argument and returns no value.

void print10() {
  printf("10");
}

Function with no argument but returns a value

For this type of functions we have void in the parameter list but we set the return type to match the type of value returned by the function.

In the following example we have function get10() which takes no argument but return an integer value 10 so, the return type of the function is set to int.

int get10(void) {
  return 10;
}

Another example of this is the main() function that we have used so far in the previous tutorials.

int main(void) {

  // some code goes here...

  return 0;
}

Function with argument but no return value

In this type of functions we have the return type set to void but the parameter list is set to accept some argument.

In the following example we have a function getNumber() which takes an integer value as argument but returns no value.

void getNumber(int num) {
  printf("Number: %d", num);
}

Function with argument and returns a value

In this type of functions we set both the parameter list and the return type.

In the following example we have a getArea() function which takes length and width of type float as argument and returns the area of type float.

float getArea(float length, float width) {
  return length * width;
}

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT