开发者

What causes a compiler error while doing a bitwise &?

I have a char pointer pointing to a char:

char *a = 'A';

And while doing a bitwise &:

*a & 0x11

I am getting a compilation error. What could be the re开发者_JAVA技巧ason for this error?


a is a variable pointing to the character at memory location 65. Operating systems usually do not allow access to such addresses and give you a segmention violation.

If you declare a not as a pointer, then it works.

char a = 'A';
char b = a & 0x11;
printf ("%x %x\n", a, b);

Still, the result depends on the signedness of char and the used character set.


You are incorrectly storing a character ('A', single quotes) into a pointer to char. You can fix this by storing a pointer to a string ("A", double quotes) though in this case, you will also need to add const since those strings are constants.

 const char *a = "A";
 char v = (*a) & 0x11;


The way it's done is

char i='A';
char *a = i;

or

char i='A';
char *a;
a=&i

Pointer can only store the address.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜