小编Jai*_*esh的帖子

为什么使用void指针来解除引用数据类型的变量?

使用void指针取消引用float变量:

#include <stdio.h>

int main() {
    float a = 7.5;
    void *vp = &a;
    printf("%f", *(float*)vp); /* Typecasting a void pointer to float for dereference */
    printf("\n");
}
Run Code Online (Sandbox Code Playgroud)

输出: 7.500000

使用整数指针取消引用变量:

#include <stdio.h>

int main() {
    float a = 7.5;
    int *ip = &a;
    printf("%f", *(float*)ip); /* Typecasting an int pointer to float for dereference */
    printf("\n");
}
Run Code Online (Sandbox Code Playgroud)

输出: 7.500000

在两者中,输出都是相同的.当我们能够通过类型转换普通指针来解决不同的数据类型变量时,是什么原因?

c types type-conversion void-pointers

8
推荐指数
2
解决办法
1272
查看次数

打印char的十进制值

用于打印char的十进制值的程序:

#include<stdio.h>

int main(void){

  char ch = 'AB';
  printf("ch is %d\n",ch);

}
Run Code Online (Sandbox Code Playgroud)

为什么打印第二个字符的十进制值,为什么不是第一个字符的十进制值?

输出: ch is 66

c

0
推荐指数
1
解决办法
1743
查看次数

我是c编程的初学者,需要帮助sizeof()字符串常量?

/**** Program to find the sizeof string literal ****/

#include<stdio.h>

int main(void)
{
printf("%d\n",sizeof("a")); 
/***The string literal here consist of a character and null character,
    so in memory the ascii values of both the characters (0 and 97) will be 
    stored respectively  which are found to be in integer datatype each 
    occupying 4 bytes. why is the compiler returning me 2 bytes instead of 8 bytes?***/

return 0;
}
Run Code Online (Sandbox Code Playgroud)

输出:

2
Run Code Online (Sandbox Code Playgroud)

c sizeof type-conversion string-literals implicit-conversion

-4
推荐指数
1
解决办法
80
查看次数