Page 95 - Modular_V2.0_C++_Flikpbook
P. 95
return (j);
}
Program 6: To print the alphabet using a function.
#include<iostream.h>
DOSBox 0.74, Cpu speed: max 100% cycles, Frameskip 0, Program:
#include<conio.h>
Alphabets from A to Z:
void printAlphabets(); A B C D E F G H I J K L M N O P Q R S T U V
void main() W X Y Z
{
clrscr();
cout<< "Alphabets from A to Z:\n";
printAlphabets();
getch();
}
void printAlphabets()
{
char letter;
for(letter = 'A'; letter <= 'Z'; letter++)
{
cout<< letter << " ";
}
}
Recap
A function is a block of organised and reusable code used to perform a particular task.
Built-in functions are predefined functions provided by C++.
C++ allows you to create your own functions which are known as user-defined functions.
The parameters passed at the time of declaring a function are called formal parameters.
There are two methods to call a function: call by value and call by reference.
The scope of a variable means how different parts of the program can access that variable.
Exercise
A. Tick ( ) the correct option.
1. Which of the following is a block of code to perform a particular task?
a. Function b. Header file
c. Operator d. None of these
2. Which of the following is also called predefined function?
a. Built-in b. User-defined
c. Both a and b d. None of these
93
Functions in C++

