C++ Programming - Objects and Classes - Discussion
Discussion Forum : Objects and Classes - Programs (Q.No. 11)
11.
What will be the output of the following program?
#include<iostream.h>
class IndiaBix
{
static int count;
public:
static void First(void)
{
count = 10;
}
static void Second(int x)
{
count = count + x;
}
static void Display(void)
{
cout<< count << endl;
}
};
int IndiaBix::count = 0;
int main()
{
IndiaBix :: First();
IndiaBix :: Second(5);
IndiaBix :: Display();
return 0;
}
Discussion:
6 comments Page 1 of 1.
Pradeep said:
1 decade ago
All are static functions it can be called through scope resolution operator only. So all the static member function calls are valid. Hence the output (At the first call count is initialized to 10 and in the second call its incremented by 5).
Priya said:
1 decade ago
Because static variables values are persists all over the program, so value is 10 & then it is incremented by 5.
NaSr Zayed said:
1 decade ago
The correct answer is 15 not the program will report compile time error.
Richa said:
8 years ago
count =10 and int 5 ,add two value=15, and reutrn type is int.
Sharukh said:
6 years ago
How it is incremented by 5.
Please, can anyone tell me?
Please, can anyone tell me?
Rajput said:
1 decade ago
How came I didn't get that can anyone explain this ?
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers