Page 94 - Modular_V2.0_C++_Flikpbook
P. 94
You can also use the scope resolution operator (::) two consecutive colons as follows:
#include<iostream.h>
#include<conio.h>
int num = 50;
DOSBox 0.74, Cpu speed: max 100% cycles,
void main()
Local variable num = 100
{ Global variable num = 50
int num = 100;
clrscr();
cout<< "Local variable num = " << num << "\n";
cout<< "Global variable num = " << ::num;
getch();
}
MORE SOLVED PROGRAMS
Program 5: To print the square of the number if the number is greater than or equal to 10.
Otherwise, print the number by multiplying it with 2.
#include<iostream.h>
#include<conio.h>
int add(int);
void main() DOSBox 0.74, Cpu speed: max 100% cycles,
{ Enter a numer: 5
Result: 10
int num, a;
clrscr();
cout<< "Enter a number: "; DOSBox 0.74, Cpu speed: max 100% cycles,
cin>> num; Enter a numer: 11
Result: 121
a = add(num);
cout<< "Result: " << a;
getch();
}
int add(int j)
{
if(j >= 10)
{
j = j * j;
}
else
{
j = j * 2;
}
92
Touchpad MODULAR (Ver. 2.0)

