cm"; cout << "\n Area of the semicircle is " << area << " sq.cm"; Output: Enter Radius (in cm): Perimeter of the semicircle is . cm Area of the semicircle is . sq.cm Illustration . : C++ program to find the perimeter and area of a semi circle Chapter Page - - .
. The Access modifier const const is the keyword used to declare a constant. You already learnt about constant in the previous chapter. const keyword modifies / restricts the accessibility of a variable.
So, it is known as Access modifier. For example, int num = ; The above statement declares a variable num with an initial value . However, the value of num can be changed during the execution. If you modify the above definition as const int num = ; the variable num becomes a constant and its value will remain throughout the program, and it can never be changed during the execution.
#include <iostream> using namespace std; int main() const int num= ; cout << "\n Value of num is = " << num; num = num + ; // Trying to increment the constant cout << "\n Value of num after increment " << num; In the above code, an error message will be displayed as “Cannot modify the const object” in Turbo compiler and “assignment of read only memory num” in Dev C++. . . References A reference provides an alias for a previously defined variable.
Declaration of a reference consists of base type and an & (ampersand) symbol; reference variable name is assigned the value of a previously declared variable. Syntax: <type> <& > = < >; #include <iostream> using namespace std; int main() int num; int &temp = num; //declaration of a reference variable temp num = ; cout << "\n The value of num = " << num; cout << "\n The value of temp = " << temp; The output of the above program will be The value of num = The value of temp = Illustration . : C++ program to declare reference variable Chapter