#include "stdio.h"
#include "conio.h"
union longtochar
{
char ch[4];
int iKey;
};
typedef union longtochar _LTC;main()
{
int iloop;
_LTC ltcKey;
ltcKey.iKey= 5310;
for (iloop = 0;iloop < 4;iloop++)
{
ltcKey.ch[iloop] = ltcKey.ch[iloop]&0x1f;
printf("%i\n",ltcKey.ch[iloop]);
}
getch();
}
其中会打印出
30
20
3
18
请问java该如何实现?结果也是30 20 3 18
#include "conio.h"
union longtochar
{
char ch[4];
int iKey;
};
typedef union longtochar _LTC;main()
{
int iloop;
_LTC ltcKey;
ltcKey.iKey= 5310;
for (iloop = 0;iloop < 4;iloop++)
{
ltcKey.ch[iloop] = ltcKey.ch[iloop]&0x1f;
printf("%i\n",ltcKey.ch[iloop]);
}
getch();
}
其中会打印出
30
20
3
18
请问java该如何实现?结果也是30 20 3 18
你好歹也加点注释嘛,或者直接讲需求也可以啊。
21
19
17
16我C语言太差了=。=
我也不明白C怎么这样,java初始可都是0啊,哪有什么随机分配啊,头疼...
class Main
{
char[] ch;
int iKey; public static void main(String[]args)
{
Main l=new Main();
l.ch=new char[4];
l.iKey=5310;
int iloop;
for (iloop = 0;iloop < 4;iloop++)
{
l.ch[iloop] = (char) (l.ch[iloop]&0x1f);
System.out.print(l.ch[iloop]);
}
}
}
再逐行按有符号十进制形式打印char数组元素久违了C语言,数组元素初始值是0吧?
#include "stdio.h"
#include "conio.h"main()
{
int i;
char c[4];
for (i = 0;i < 4;i++)
{
printf("%i\n",c[i]);
}
getch();
}
gcc 4.4.0
vc2008 express (Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 15.00.30729.01 for 80x86)Windows XP 输出都是
30
20
0
0