输出结果如何是JACK?

#include <stdio.h>

int main()
{
    void *vp;
    char ch = 74, *cp = "JACK";
    int j = 65;
    vp = &ch;
    printf("%c", *(char*)vp);
    vp = &j;
    printf("%c", *(int*)vp);
    vp = cp;
    printf("%s", (char*)vp + 2);
    return 0;
}

最佳答案

vp = &ch;
printf("%c", *(char*)vp);


输出代码为74(J)的字符

vp = &j;
printf("%c", *(int*)vp);


输出代码为65(A)的字符

vp = cp;
printf("%s", (char*)vp + 2);


输出偏移量为2(CK)的字符串“ JACK”

=>杰克

关于c - C指针输出以下需要说明,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32167241/

10-10 18:23