We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 4
Nested Loops
Any loop statement can be nested with in any other loop
statement. We can say that a loop may contain another
loop in its body. This form of a loop is called nested loop.
In nested loop, two loops, i.e. inner loop and otiter loop are
executed. But the inner loop must terminate before the
outer loop.
4. Jump Statements
The jump statements unconditionally transfer program
control within a function. The various jump statements are
as follows: Bat
(i) goto Statement This statement is used to alter the
program execution sequence by transferring the
control to some other part of the program.
Syntax i
goto label;
Here, the label is a C++ identifier used to label the
destination, where the control is to be transferred the
target statement will appear as
label: statement:
(i) continue Statement This statement jumps over all the
Test of statements in the loop’s block and goes to the
Next statement after the loop. The continue statement
~ Scanned with CamScannerFunctions
A function is a self-contained block of statements, which
are kept together to perform a specific task in related
manner. A function has a name and it has a property, ie.
reusable. It can be executed from as many different points
ina C ++ program as required, In C+, the main( ) itself is
a function that means the main function is invoking the
other functions to perform various tasks.
There are two types of functions in C-+ are as follows:
Library Functions
Library functions are the predefined functions in
programming system. These are also known as in-built
functions Some of the library or in-built functions
according to their header files are described below:
Header File Functions
‘tdio.h (Standard input and char gets(char str{ })
output) int puts(char str })
int gete(char str{ })
int get( )
char getchar( )
‘typesh (Character tests) int isalnum( int i)
int isalpha(int i)
int isdigit(int i)
int istower(int i)
int isupper(int i)
int tolower(int i)
int toupper(int i)
stringh (String operations) char strepy(char ste1[ J, char str2[ ])
char strcat(char steI{ J, str2{ })
int strlen(char str{ 1)
. int stremp(char str1f J, st2[ })
i {nt strempi(char str[], char str2{ 1)
char strrev(char str{ J)
char strupr(char ste{ })
char strlwe(char ste })
Scanned with CamScannerHeader File Funetions 5,
Fath (Mathemadical double fabs(double x): °~ 03 boes
‘e double pow(double x, double y)
double sqrt(double x)
double sin(double x)
double cos(double x)
int abs(int x)
double log(double or float x)
double frexp(double x, int y)
double exp(double x)
stdlib.h (Standard library in nt mn =|
finan) Te enn hs
eponeeun ee et eminent ype ae
User Defined Functions
C++ provides facility for programmers to define their own
functions according to their requirements. The functions
defined by programmers are known as user defined
functions. te
To add a user defined function in the program, there are
three necessary components as given here: sn
Retumtype p— Funconname |
void Funt 1 Function prétotyping
vod cig TO
oe ee
‘Semicolon
Function name
} no semicolon
Return __ void Fun()
type ry
Function Function
body definition
(i) Function Prototyping
It describes the function interface to the compiler by giving
details such as the name of function, number and type of.
arguments and the type of return values.
Basically, each user defined function needs to be declared
before its usage in the program, This declaration is called as
function prototype or function declaration. The function
prototype can be given anywhere in the program, ie. inside
penoutside of any function of the program. a
Funetion prototype isa declaration statement in the
is of the following form:
program and
function_name(datatype argl. datatype
return_type arg2, .... datatype argN):
Scanned with CamScannerHere,
« ‘The return_type refers to type of value,
« ‘The function_name can be any name,
«+ argh, arg2, + argN are called formal arguments or
formal parameters as they simply represent the name of )
the data items that are transferred to the function from
the calling function.
.. (ii) Defining a Function
‘A function definition has a name, a parentheses pair
containing zero or more parameters and a body. For each
parameter, there should be a corresponding declaration that
occurs before the body.
‘The general format of function definition is as follows:
return_type function_name(datatype arg i
datatype arg2, ...)
{
11 body of function
; return(expression) ;
eg.
Formal
[argument
Data type of the(Ciong int) “
variable to be (int n)
returned b
thetunston int Function name
long int prod=1; Local variables
Compound
statements
return(prod);
(iii) Calling a Function
A function can be called by specifying its name followed by
list of arguments separated by commas, enclosed in |
+ parentheses. If no arguments are required, then these must
be empty pair of parentheses. The function, which calls any
other function is known as caller function and this
function is known as called function.
eg. factorial (5):
te
Scanned with CamScanner