473,385 Members | 1,901 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Difference between implementations of union

please let me know why there is different outputs in the programs given below
Expand|Select|Wrap|Line Numbers
  1. #include<iostream.h>
  2. union a
  3. {
  4.     int i;
  5. };
  6. a u;
  7. void main()
  8. {
  9.   cout<<i;
  10. }
  11.  
in the above program output is 0
Expand|Select|Wrap|Line Numbers
  1. #include<iostream.h>
  2. union a
  3. {
  4.    int i;
  5. };
  6. void main()
  7. {
  8.   a u;
  9.    cout<<i;
  10. }
  11.  
in the above program output is 18125

please explain the outputs
Sep 7 '07 #1
2 1163
ilikepython
844 Expert 512MB
please let me know why there is different outputs in the programs given below
code: (cpp)
#include<iostream.h>
union a
{
int i;
};
a u;
void main()
{
cout<<i;
}

in the above program output is 0

#include<iostream.h>
union a
{
int i;
};
void main()
{
a u;
cout<<i;
}

in the above program output is 18125

please explain the outputs
First, your program should be "int main()" and you should include:
Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
instead of
Expand|Select|Wrap|Line Numbers
  1. #include <iostream.h>
Also, those programs don't compile. Maybe add this:
Expand|Select|Wrap|Line Numbers
  1. cout << u.i << endl;
  2.  
I think that the values are garbage since you never initialize i to anything.
Sep 7 '07 #2
Global and local initialization of i..
Sep 7 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Mickel Grönroos | last post by:
Hi! Are there any standard list methods for getting the intersection and difference of two lists? (The union is easy ("list1.extend(list2)"), unless you want it to contain unique values.) ...
34
by: yensao | last post by:
Hi, I have a hard time to understand difference and similarities between Relational database model and the Object-Oriented model. Can somebody help me with this? Thank you in advance. ...
10
by: xixi | last post by:
we are using db2 udb v8.1 on windows, i would like to know whether we have tool or way to compare two tables on same database for data difference. thanks. (same ddl, different data, try to compare...
4
by: csudha | last post by:
Hi All, Can you give me the example code which explains difference between Structures and Union. As a newbie please do the needful. Thanks, csudha.
4
rsrinivasan
by: rsrinivasan | last post by:
Hi, What is the difference between UNION and UNION ALL. I refered some document. But i did not get any clear idea on that. Thanks,
45
by: anto frank | last post by:
hi friends, is ther any difference in array in c and array in c++?
0
by: manish sahu | last post by:
difference between structure and union ,, can anyone help me?
6
by: npd1 | last post by:
what is the difference between structure & union
6
by: Ravikiran | last post by:
Hi, I want know the differences between Unions and Structures in C programming. Thank you..
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.