C++ Programming - Constructors and Destructors - Discussion

Discussion Forum : Constructors and Destructors - Programs (Q.No. 6)
6.
Which of the following statement is correct about the program given below?
#include<iostream.h> 
class IndiaBix
{
    int *p; 
    public:
    IndiaBix(int xx, char ch)
    {
        p  = new int(); 
        *p = xx + int(ch); 
        cout<< *p;
    }
    ~IndiaBix() 
    {
        delete p;
    }
};
int main()
{
    IndiaBix objBix(10, 'B'); 
    return 0;
}
The program will print the output 76.
The program will print the output 108.
The program will print the output garbage value.
The program will report compile time error.
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
9 comments Page 1 of 1.

Ravi said:   1 decade ago
@Akanksha.

Char to integer conversion: We have built in ASCII value range i.e. A to Z is 65 to 90. So here in above program we have 'B' that's mean its integer value is 66.

Minni said:   1 decade ago
Here the character is converted into int i.e. 'B'=66 which is added to the xx value 10 and thus we get the output 76.

Madhu said:   7 years ago
It Should print some garbage value I guess as *p prints address.

Please, someone revert back to clear this doubt.

Balu said:   1 decade ago
Pointer variable print the address of the content then how it prints the value?

Rohit said:   9 years ago
How output comes to 76? It's only because ASCII value of B is 66.

Anon said:   1 decade ago
Shouldn't p be assigned to an address in c as in p=&a ?

Raj said:   7 years ago
*p is not print address it prints value of p=10+66=76.

Akanksha said:   1 decade ago
How to convert character into integer?

DOMINIC said:   8 years ago
BECAUSE ASCII VALUE OF B is 066.

Post your comments here:

Your comments will be displayed after verification.