小编pin*_*rog的帖子

超过 15 个字符的字符字符串出错

为什么 gcc 不允许我使用大于 15 的字符维数?

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main()
{
    char alphabet[]={'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
    int dim_alph;
    dim_alph=strlen(alphabet);
    printf("%s has %d characters\n", alphabet, dim_alph);
    return 0;
}`
Run Code Online (Sandbox Code Playgroud)

它在字符串和维度上都给了我无效的输出(如果我停在“P”字符而不是“O”字符上)

c printf c-strings char undefined-behavior

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

标签 统计

c ×1

c-strings ×1

char ×1

printf ×1

undefined-behavior ×1