structure

shouldn't be the output be a garbage value?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#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;
}
Last edited on
Correct. y was never initialized.
You should use a more recent compiler. I see that you are using <iostream.h>
AbstractionAnon wrote:
Correct. y was never initialized.
y is assigned a value before it is read from. (See line 11.)

However, line 12 results in undefined behavior and as a result y's value could be anything, including whatever value the OP expected it to be.
Last edited on
cire wrote:
y is assigned a value before it is read from. (See line 11.)

True, but Function() is never called, therefore, y has not been set when Display() is called at line 22.


Aha.
Topic archived. No new replies allowed.