c中的指针声明

use*_*793 2 c int char

我正在使用gcc 4.8.1,我无法理解以下程序的输出.

#include<stdio.h>
int main()
{

    char* a, b, c;
    int* d, e, f;
    float* g, h, i;
    printf("Size of a %zu and b %zu and c %zu \n", sizeof(a), sizeof(b), sizeof(c));
    printf("Size of d %zu and e %zu and f %zu and int is %zu \n", sizeof(d), sizeof(e), sizeof(f), sizeof(int*));
    printf("Size of g %zu and h %zu and i %zu and float is %zu \n", sizeof(g), sizeof(h), sizeof(i), sizeof(float));
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

输出是

Size of a 4 and b 1 and c 1
Size of d 4 and e 4 and f 4 and int is 4
Size of g 4 and h 4 and i 4 and float is 4
Run Code Online (Sandbox Code Playgroud)

我的问题是为什么bc不是char*类型,而在int和的情况下也是可能的float.我想知道C语法如何拆分声明.

tml*_*len 6

在像这样的宣言中

char* a, b, c;
Run Code Online (Sandbox Code Playgroud)

只有类型char用于所有变量,而不是它是否是指针(*符号).如果这样使用(等效)语法使其更清晰:

char *a, b, c;
Run Code Online (Sandbox Code Playgroud)

要定义3个指针:

char *a, *b, *c;
Run Code Online (Sandbox Code Playgroud)

或者在经常使用多个指向char的指针的情况下,可以执行typedef:

typedef char* char_buffer;
char_buffer a, b, c;
Run Code Online (Sandbox Code Playgroud)