Call by value and Call by reference in C Programming

Call by value and Call by reference in C are two ways to pass arguments in a function

Lets see above one by one

Call by value

Whenever we call a function and passes the value of variable to the called function is called call by value.

OUTPUT

Call by reference

Whenever we call a function and passes the reference of variable to the called function is called call by reference.

In the call by reference, to pass the reference of the variable we use pointer.

OUTPUT

Functions in JavaScript

What is a Function?

  • A function is a block of code or a subprogram designed to perform a particular task.
  • Function is executed only when it is called. This is called invoking/calling a function. Thus it eliminates writing the same code again and again.
  • Values can be passed into functions and used within the function body.

Function always returns a value, if no return type is specified, the function will return undefined .

JavaScript Function Syntax

JavaScript supports 4 types of function invoking:

  1. Function having no arguments and no return value
  2. Function having arguments and no return value
  3. Function having return value and argument(s)
  4. Function having return value but no arguments

Function having no arguments and no return value

In JavaScript, if there’s no specified return type, the function will return undefined. Consider the following example:

R

Result

Function having arguments and no return value

Consider the following example:

Result

Here the ‘return’ statement is missing. But arguments are passed to the function and used in the block of code.

Function having return value and arguments

Result

Function having return value but no arguments

Result