In this program, we are going to see how to call & increment COUNT 3 times in C++ Programming Language.
The Code given below can be used in TURBO C++ Compilers: -
//C++ program to call and increment COUNT 3 times.
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
class Class
{
public:
static int count;
Class();
};
Class::Class()
{
count++;
}
int Class::count = 0;
void main()
{
system("cls");
cout << "Initial value of count:- " << Class::count;
Class obj1, obj2, obj3;
cout << "\nCount value after 3 objects:- " << Class ::count;
getch();
}
//.........Coded by YASH ALAPURIA
The Code given below can be used in gcc/g++ Compilers: -
//C++ program to call and increment COUNT 3 times.
#include<iostream>
#include<stdlib.h>
using namespace std;
class Class
{
public:
static int count;
Class();
};
Class::Class()
{
count++;
}
int Class::count = 0;
int main(void)
{
system("cls");
cout << "Initial value of count:- " << Class::count;
Class obj1, obj2, obj3;
cout << "\nCount value after 3 objects:- " << Class ::count;
return 0;
}
//.........Coded by YASH ALAPURIA
#ENJOY CODING
Post a Comment
FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP