Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6844351
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:21:57+00:00 2026-05-27T00:21:57+00:00

For the union declaration below union a { int i; char ch[2]; }; union

  • 0

For the union declaration below

union a
{
    int i;
    char ch[2];
};
union a u;
u.ch[0] = 3;
u.ch[1] = 2;

Since i and ch store in the same place, i should now be <binary rep. of 3> concatenated with <binary rep. of 2>. However, it is stored in the reverse order.

printf("%d",i);

gives 515.
Why so??

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T00:21:58+00:00Added an answer on May 27, 2026 at 12:21 am

    The result depends on the endianness of the machine you are trying your program on.

    It is 515 on a little endian machine Intel i686:

    $ uname -m
    i686
    $ ./a.out
    515
    

    and is 770 on a bin endian machine like Sparc:

    $ uname -m
    sun4v
    $ ./a.out
    770
    

    This happens because the endianess will determine if ch[0] will be higher order byte (in big endian) or lower order byte (in little endian) of i.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I define a union like this: #include <stdio.h> int main() { union u
I had a need to declare a union inside a structure as defined below:
typedef union epoll_data { void *ptr; int fd; __uint32_t u32; __uint64_t u64; } epoll_data_t;
How to 'union' 2 or more DataTables in C#? Both table has same structure.
I am using the following union declaration in SSE2. typedef unsigned long uli; typedef
If I declare a Union as: union TestUnion { struct { unsigned int Num;
union LowLevelNumber { unsigned int n; struct { unsigned int lowByte : 8; unsigned
typedef union _Value { signed char c; unsigned char b; signed short s; unsigned
I am building a class that has a union for its matrix data, however,
If UNION ALL is an addition in T-SQL. What is the equivalent of subtraction?

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.