C++ Programming - Objects and Classes - Discussion

Discussion Forum : Objects and Classes - Programs (Q.No. 10)
10.
Which of the following statement is correct about the program given below?
#include<iostream.h> 
class IndiaBix
{
    int x; 
    float y; 
    public:
    void Function()
    {
        x = 4; 
        y = 2.50; delete this;
    }
    void Display()
    {
        cout<< x << " " << y;
    } 
}; 
int main()
{
    IndiaBix *pBix = new IndiaBix();
    pBix->Function(); 
    pBix->Function(); 
    pBix->Display(); 
    return 0; 
}
The program will print the output 4 2.5.
The program will print the output 4.
The program will report runtime error.
The program will report compile time error.
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
10 comments Page 1 of 1.

Shatya kesarwani said:   8 years ago
IndiaBix *pBix = new IndiaBix();

What is this?
We don't have constructor then why we call IndiaBix();, and also if we do this then what will do?

Keshav Khetriwal said:   1 decade ago
At the first call of Function() from main the object pBix gets deleted. So any further function calls for that object will cause runtime error.
(1)

Anis said:   1 decade ago
It is right to say that obj pbix get destroy and it is not accessible on 2nd function call.

Ganesh singh said:   1 decade ago
It is run time error because new allocate memory during run time.

Mohmmad Mohsin said:   1 decade ago
While I run this program in Dev CPP it gives simply 4 2.5 output.

SAM said:   1 decade ago
Why specifically runtime ? why is it not a compile time error ?

Vishal Das said:   4 years ago
@Shatya.

It is handled by default constructor by a complier.

Ravinder Kumar said:   1 decade ago
Yes also in code blocks showing 4 2.5 output.

Aya said:   4 years ago
why run time error occur? Please eplain.

Abhishek said:   1 decade ago
Why it is run error?

Post your comments here:

Your comments will be displayed after verification.