0
Well, in a programming exercise I was given the following program, and I asked what is your output
using namespace std;
union U1 {
union U2{
unsigned a: 3;
unsigned b: 4;
unsigned c: 1;
}u2;
int d;
void Exibe(unsigned, unsigned, unsigned, int);
}u1;
int main(){
u1.u2.a=2;
u1.u2.a<<=1;
u1.u2.b=16;
u1.u2.b-=4;
u1.u2.c=(u1.u2.b)>>3;
u1.d=17;
cout << u1.u2.a << " " << u1.u2.b << " " << u1.u2.c << " " << u1.d << endl;
}
After the execution of the code the output is '1 1 1 17' , my doubt is on why of this output, I researched on bit displacement and joining with the little that was given in class still could not understand, could help me to understand?
Did you execute the code? If yes, at least you have the output. Asking about the meaning/reason of the output is something quite different, there yes more valid. I’m sorry to comment, but the way the question looks like programming exercise + typing and compiling laziness. You are welcome here, but note that this site is not a forum. If not yet, do the [tour].
– Luiz Vieira
Yes, I ran, the output is '1 1 1 17' , is that I did not understand even what is the logic of this output, I researched about bit displacement but still I am lost. And yes, it is a question of a programming exercise where all the questions are more or less in this context, I asked for help on this to understand how to do.
– Sávio Bezerra
Ok. Then edit the question, and add to it the information you gave me. Then I vote to reopen. ;)
– Luiz Vieira