Example:1
Give output of the following program
#include <iostream>
#include<conio.h>
using namespace std;
class sample
{
private:
static int a;
public:
void disp();
};
int sample::a; //1
//int sample::a=100; //2
void sample::disp()
{
cout<<"a= "<<a<<endl;
}
int main()
{
/* clrscr(); */
sample e;
e.disp();
getch();
return(0);
}
Output:
// if statments 1 is active
a= 0
// if statments 2 is active
a= 100
Example:2
Give output of the following program
#include <iostream>
#include<conio.h>
using namespace std;
class sample
{
private:
static int a;
public:
void disp();
};
int sample::a; //1
//int sample::a=100; //2
void sample::disp()
{
for(int i=0;i<=10;i++)
a+=i; //a=a+i;
cout<<"a= "<<a<<endl;
}
int main()
{
/* clrscr(); */
sample e;
e.disp();
getch();
return(0);
}
Output:
//if statement 1 is active
a= 55
//if statement 2 is active
a= 155




