You are on page 1of 5

APEEJAY INSTITUTE OF MANEGMENT TECHNICAL CAMPUS

ASSIGNMENT 1

OOPS USING C++

SUBMITTED
SUBMITTED BY
Dr. Ashu Gupta
Thakur
Assistant professor
154021

TO:
Taniya
Bca II

Q What are functions ? Explain the concept of


inline function and default argument with the help
of suitable example ?

Functions
A function is a group of statements that together perform a task. Every C++ program
has at least one function, which is main(), and all the most trivial programs can
define additional functions.
You can divide up your code into separate functions. How you divide up your code
among different functions is up to you, but logically the division usually is so each
function performs a specific task.
A function declaration tells the compiler about a function's name, return type, and
parameters. A function definition provides the actual body of the function.
The C++ standard library provides numerous built-in functions that your program
can call. For example, function strcat() to concatenate two strings,
function memcpy() to copy one memory location to another location and many more
functions.
A function is knows as with various names like a method or a sub-routine or a
procedure etc.

C++ Inline Function


C++ inline function is powerful concept that is commonly used with classes. If a function is
inline, the compiler places a copy of the code of that function at each point where the function
is called at compile time.
Any change to an inline function could require all clients of the function to be recompiled
because compiler would need to replace all the code once again otherwise it will continue with
old functionality.
To inline a function, place the keyword inline before the function name and define the
function before any calls are made to the function. The compiler can ignore the inline qualifier
in case defined function is more than a line.
A function definition in a class definition is an inline function definition, even without the use
of the inline specifier.

Defult Arguments
Defult Arguments
One of the most useful facilities available in C++ is the facility to defined
default argument values for functions. In the function prototype declaration,
the default values are given. Whenever a call is made to a function without
specifying an argument, the program will automatically assign values to the
parameters from the default function prototype declaration. Fault arguments
facilitate easy development and maintenance of program.
PROGRAM
A program find the sum of the given numbers using default argument
declaration.
/ /default argument declaration
#include <iostream.h>
void sum ( int a, int b, int c= 6, int d = 10);
void main ( )
{
int a, b, c, d;
cout << enter any two numbers \n;
cin >> a >>b;
sum (a, b) ; / / sum of default values
}
void sum (int a1, int a2, int a3, int a4)
{
int temp;
temp = a1 + a2 + a3 + a4;
cout << a = << a1 << endl;
cout << b = << a2 << endl;
cout << c = << a3 << endl;
cout << d = << a4 << endl;

cout << sum = << temp;


}
Output of the above program
enter any two numbers
11 21
a = 11
b = 21
c=6
d = 10
sum = 48

You might also like