C Foundation

What is C? C Compiler Installation C Extensions C Compiler C Interpreter C Program Structure

C Basics

C Keywords C Data Types C Identifiers C Variables C Constant C Escape Sequences C Constant and Volatile C Typecast

Operators

What is Operator C Comma Operator C Arithmetic Operators C Relational Operators C Logical Operators C Bitwise Operators C Conditional Operators C : : Operator C Operator Priority

Basic IO's

Basic IO's C Formatted Functions C Unformatted Functions C Common Functions

Control Statements

What is Control Statement C if Statement C if else Statement C Nested if Statement C Else if Statement C Break Statement C Continue Statement C Switch Statement C Goto Statement

Looping

What is Control Loop C for Loop C Nested for Loop C while Loop C Nested while Loop C do while Loop C Nested do while loop

Functions

What is Function C User Defined Functions C Recursion C Passing Parameters

Scope

Scope C Local Scope C Global Scope

Storage Classes

What is Storage Class C Auto C Extern C Static C Register

Array

What is Array C One Dimensional Array C Two Dimensional Array C Multi Dimensional Array C Arrays Of Strings

String

What is String C String Functions

Pointer

What is Pointer C Pointers Arithmetic C Pointer to Pointer C Pointers and Arrays C Pointers and Strings C Pointer to Functions Void Pointers Null Pointers C Null and Void Pointer

Structure

What is Structure C Struct within Struct C Array within Structure C Pointer to Structure C Structure and Function C Enum C Bitfield Structure C Type def

Union

What is Union

Files

What is File C read a file C write a file C File Handling C Error Handling C Low Level Disk I/O C Other file functions

Memory Allocation

What is Memory Allocation C Malloc() C Calloc() C Free() C Realloc() C Coreleft()

C Reference

All ASCII Code Basic C Questions

C Interview

C Interview Sets All Star Patterns All Number Patterns All Alphabet Patterns All Series Patterns
The ones who are crazy enough to think they can change the world are the ones who do.
- Steve Jobs

C User Defined Functions

What Is User Defined Function

" What you have to do when I call you"
yes, the above quotes clearly define the purpose of user defined function. By speaking conceptually, a programmer can define their own sets of code inside a function and use it for n number of times using its function name.

C User Defined Functions

Types

The user-defined functions are classified into four types, according to parameters and return value.

  • Functions without arguments but with return values
  • Functions without arguments and without return values
  • Functions with arguments but without return values
  • Functions with arguments and without return values

#1 Functions Without Arguments Without Return Values

The calling function will not send parameters to the called function and called function will not pass the return value to the calling function.

C program - Functions Without Arguments Without Return Values

function1.c
#include <stdio.h>
void add();     //function declaration
int main()
{
//main function definition
add();    //function call without passing arguments
}
//function definition
void add()
{
int a = 5, b = 10;
int c;
printf(" The values of a and b : %d %d ", a, b);
c = a + b;
printf(" \nsum : %d ", c);
//no return values to the calling function
}
  • The values of a and b : 5 10
  • sum = 15

Note:

The program illustrates that, there are no parameters passed through the calling function and no return value to the calling function main().

#2 Functions With Arguments Without Return Values

The calling function will pass parameters to the called function but called function will not pass the return value to the calling function.

C program - Functions With Arguments Without Return Values

function2.c
#include <stdio.h>
void add(int,int);     //function declaration
int main()
{
//main function definition
int sum;
int a = 5, b = 10;
printf(" The values of a and b : %d %d ", a, b);
add( a, b);    //function call with passing arguments to called function
}
// function definition
void add(int a, int b)
{
int c;
c = a + b;
printf(" \nsum : %d ", c);
//no return values to the calling function main
}
  • The values of a and b : 5 10
  • sum = 15

Note:

The program illustrates that, parameters are passed to the called function(add) from calling function(main) but no return values are passed from called function(add) to the calling function (main).

#3 Functions Without Arguments With Return Values

The calling function will not pass parameters to the called function but called function will pass the return value to the calling function.

C program - Functions Without Arguments With Return Values

function3.c
#include <stdio.h>
int add();     //function declaration
int main()
{
//main function definition
int sum;
sum = add();    //function call without passing arguments to called function
printf(" \nsum = %d ", sum);
}
// function definition
int add()
{
int c;
int a = 5, b = 10;
printf(" The values of a and b : %d %d ", a, b);
c = a + b;
return c;    //passing return values to the calling function main
}
  • The values of a and b : 5 10
  • sum = 15

Note:

The program illustrates that, no parameters are passed to the called function(add) from calling function(main) but return value is passed from called function(add) to the calling function (main). The return values is assigned to the variable sum.

#4 Functions With Arguments With Return Values

The calling function will pass parameters to the called function and called function also pass the return value to the calling function.

C program - Functions With Arguments With Return Values

function4.c
#include <stdio.h>
int add(int, int);     //function declaration
int main()
{
//main function definition
int sum;
int a = 5, b = 10;
printf(" The values of a and b : %d %d ", a, b);
sum = add( a, b);    //function call with passing arguments
printf(" \nsum = %d ", sum);
}
// function definition
int add(int a, int b)
{
int c;
c = a + b;
return c;    //passing return values to the calling function main
}
  • The values of a and b : 5 10
  • sum = 15

Note:

The program illustrates that, parameters are passed to the called function (add) from calling function (main) and return value is passed from called function (add) to the calling function (main). The return values is assigned to the variable sum.

Report Us

We may make mistakes(spelling, program bug, typing mistake and etc.), So we have this container to collect mistakes. We highly respect your findings.

Report

We to update you