小编Tho*_*mas的帖子

printf()打印错误的值

这是我的完整代码,每当我运行它时,它都会打印随机的负值,不确定是否出了问题。使用Ubuntu来运行和“ gcc -Wall -Wextra test.c”

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

unsigned int x = 10;
unsigned int y = 16;
unsigned int p = x + y;

printf("%d\n", &p);

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

c printf arithmetic-expressions

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

在C中设置2D字符数组时出现SegFault

我正在尝试设置一个填充有'$'字符的10x10网格,然后进行打印。

    char **plot;
    plot = (char**)calloc(100, sizeof(char));

    int i,j;

    for (i=0; i< 10; i++) {
            for(j=0; j<10; j++){
                    plot[i][j] = '$';
            }
    }

    for (i=0; i<10; i++) {
            for(j=0; j<10; j++) {
                    printf("%c", plot[i][j]);
            }
    }

    free(plot);
Run Code Online (Sandbox Code Playgroud)

到目前为止,这是我的代码,当我运行此代码时,我遇到了分段错误。

c arrays calloc

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

标签 统计

c ×2

arithmetic-expressions ×1

arrays ×1

calloc ×1

printf ×1