Interview Question

  • -
    0
    of 0 votes
    7
    Answers

    main(){
    union d{
    unsigned int a:1;
    unsigned int b:3;
    unsigned c:2;};
    union d aa;
    aa.b=6;aa.c=2;aa.a=1;
    printf("%d %d %d",aa.a,aa.b,aa.c);}
    What does the above code output?

    - Barney on July 03, 2012 in United States Report Duplicate | Flag
    C

Country: United States


Comment hidden because of low score. Click to expand.
2
of 2 vote

Answer would be 1 7 3, check

- Luv on July 03, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

1 3 7

- arun on July 03, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

there would be max 3 bit.
aa.b=6=110
aa.c=2=10
aa.a=1

now final bit 111
so aa.a=1
aa.b=11=3
aa.c=111=7

- arun on July 03, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

can you please explain the output when input is
aa.b=1;aa.c=3;aa.a=7;

- Abhishek on July 03, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

aa.b=1=001
aa.c=3=11
aa.a=7(actually aa.a is of i bit so it take only 1)=1


so the final bit is 011

so aa.a=1=1
aa.b=011=3
aa.c=11=3

- arun on July 03, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

in gcc tha ans is
1 3 3

- arun on July 03, 2012 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

can you explain the logic?

- sakshi on July 18, 2012 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book walking you through getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More