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;
}
Discussion:
10 comments Page 1 of 1.
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)
SAM said:
1 decade ago
Why specifically runtime ? why is it not a compile time error ?
Abhishek said:
1 decade ago
Why it is run error?
Ganesh singh said:
1 decade ago
It is run time error because new allocate memory during run time.
Anis said:
1 decade ago
It is right to say that obj pbix get destroy and it is not accessible on 2nd function call.
Mohmmad Mohsin said:
1 decade ago
While I run this program in Dev CPP it gives simply 4 2.5 output.
Ravinder Kumar said:
1 decade ago
Yes also in code blocks showing 4 2.5 output.
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?
What is this?
We don't have constructor then why we call IndiaBix();, and also if we do this then what will do?
Vishal Das said:
4 years ago
@Shatya.
It is handled by default constructor by a complier.
It is handled by default constructor by a complier.
Aya said:
4 years ago
why run time error occur? Please eplain.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers