English 中文(简体)
A. 结构组合方向
原标题:array orientation in structure
  • 时间:2011-11-24 08:44:01
  •  标签:
  • c
  • unions

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??

最佳回答
问题回答

由于您重印<代码>%d,编号为<0>。 因此:

u.ch[0] = 3;

缩略语

0000 0011  // 8bits, as char is 1B

嗣后:

u.ch[1] = 2;

——

0000 0010 // 8bits, as char is 1B

而且,“当你把2和2放在一起”(:D)

  00..00                   0000 0010          0000 0011 // sizeof (int) * 8 bits
  ^^^^^^                   ^^^^^^^^^          ^^^^^^^^^
//(sizeof(int)*8-16)bits   this is the 2    this is the 3

——515 in dec.


索里,我错过那部分“hy”。 具体针对平台,您应读到Endianness,并且更具体地说,涉及Big-endian和Littleendian。 该条有一些例子。 Hint:似乎与你一样有一台低端机器。

奥凯,Ill总结了我在这里的评论:保证将阵列储存在持续记忆中。 <>Let s supposesizeof (t ) = 2,以便于解释。 因此,你

u.ch[0] = 3;
u.ch[1] = 2;

这将首先储存<代码>3,下一期将刊印<代码>2。 如你(我猜想)所期望的那样,SO是:

0000 0011 0000 0010
^^^^3^^^^ ^^^^2^^^^

外交部 页: 1 《国际持久性有机污染物公约》(http://www.un.org/Docs/journal/Ar/pdf)。

0000 0011 0000 0010

你们的机器很少是最终的,而“转让”是指:

0000 0010 0000 0011 (reversed order of the bytes!)

哪些是<代码>515的双重代表

它提供515份,因为未具体说明的行为。 没有人能够回答你的问题,而不知道你使用什么汇编者,以及编辑如何处理工会。

  • 编辑可免费在工会内任何地方储存任何数量的pa,但第一次是秘密。

  • 该方案只要求给你以与工会最后接触相应的结果。 如果你通过果园成员进入,那么只保证能够读到果园。 阅读直系成员可以给你什么东西,你可以知道什么。

  • 由于这一行为不明确,汇编者甚至不必记录如何处理这些查阅。 如果是幸运的话,他们就是这样做的。

  • 汇编者向您提供按此等编码的 by或垃圾价值,是完全有效的。





相关问题
Fastest method for running a binary search on a file in C?

For example, let s say I want to find a particular word or number in a file. The contents are in sorted order (obviously). Since I want to run a binary search on the file, it seems like a real waste ...

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

Tips for debugging a made-for-linux application on windows?

I m trying to find the source of a bug I have found in an open-source application. I have managed to get a build up and running on my Windows machine, but I m having trouble finding the spot in the ...

Trying to split by two delimiters and it doesn t work - C

I wrote below code to readin line by line from stdin ex. city=Boston;city=New York;city=Chicago and then split each line by ; delimiter and print each record. Then in yet another loop I try to ...

Good, free, easy-to-use C graphics libraries? [closed]

I was wondering if there were any good free graphics libraries for C that are easy to use? It s for plotting 2d and 3d graphs and then saving to a file. It s on a Linux system and there s no gnuplot ...

Encoding, decoding an integer to a char array

Please note that this is not homework and i did search before starting this new thread. I got Store an int in a char array? I was looking for an answer but didn t get any satisfactory answer in the ...

热门标签