qfedu-c-level/day8/homework/h6.c

18 lines
568 B
C
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// 给定一个long类型的变量赋值0x010203040506, 请按单字节方式输出这个变量的数值。
#include <stdio.h>
int main()
{
long m = 0x010203040506;
char *p = (char *)&m;
printf("sizeof(long) = %lu\n", sizeof(long)); // 8
printf("sizeof(char) = %lu\n", sizeof(char)); // 1
while (*p) // 当指针指向的值为 0 时,表示已经到达 long 类型变量的末尾
{
printf("%x ", *p); // 输出指针指向的值
p++; // 指针向后移动一个字节
}
printf("\n");
return 0;
}