C++ Programming - Objects and Classes - Discussion

Discussion Forum : Objects and Classes - Programs (Q.No. 6)
6.
What will be the output of the following program?
#include<iostream.h> 
class India
{
    public:
    struct Bix
    {
        int   x;
        float y;
        void Function(void)
        {
            y = x = (x = 4*4); 
            y = --y * y;
        }
        void Display()
        {
            cout<< y << endl;
        } 
    }B; 
}I; 
int main()
{
    I.B.Display(); 
    return 0;
}
0
1
-1
Garbage value
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
25 comments Page 1 of 3.

Paanku said:   7 years ago
It is because we have a global object.

For global objects, all members are initialised to zero.
(1)

Neha said:   7 years ago
Because y is global variable for function display and global variable value by default is zero.
(1)

Krish said:   1 decade ago
The void function was not called only display is invoked ? then how initialized y=x=(x=4*4).

How you say y=x=(x=4*4) is equal to 1?

Tanmay said:   8 years ago
The void Function (void) will not be called simply.

If we have written I.B.Function then things would have been different.

Swetha said:   8 years ago
Hello.

I'd like to assert that the main function is returning a 0,
hence, 0!.

Faree said:   9 years ago
Functions can't be defined inside a structure, so how the answer is 0?

Nikhil said:   9 years ago
How the output will be zero?

Not understand please explain it.

Scorpionsrk7 said:   9 years ago
What is the B and L in this program?

Nuzhat said:   10 years ago
y = x = (x = 4*4).

Explain above in details.

x = 4*4 = 16?

How could it 1?

Nishant sharma said:   10 years ago
Since argument type of function is void therefore it takes no arguments. Hence answer is zero.


Post your comments here:

Your comments will be displayed after verification.