小编Ari*_*n.K的帖子

为什么'for'循环条件失败?

在下面显示的代码中,没有任何内容被打印,这意味着for循环中的条件失败.可能是什么原因?

我想知道,因为当我TOTAL_ELEMENTS单独打印时,它给出了5,所以它必须是5-2=3 => -1<=3,所以它应该打印一些东西.

#define TOTAL_ELEMENTS (sizeof(array) / sizeof(array[0]))

int array[] = { 23, 34, 12, 17, 204, 99, 16 };
int main()
{
    int d;

    for (d = -1; d <= (TOTAL_ELEMENTS - 2); d++) {
        printf("%d\n", array[d + 1]);
    }

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

有人可以解释这段代码吗?

c type-conversion implicit-conversion c-preprocessor

12
推荐指数
3
解决办法
1687
查看次数

L作为增量运算符所需的值 - C.

我刚从朋友处得到一个问题.

#include<stdio.h>

void fun(int[][3]);

int main(void){
    int a[3][3]={1,2,3,4,5,6,7,8,9};

    fun(a);
    printf("\n%u",a);
    a++;//Ques 1

    printf("\n%u",a);
    printf("%d",a[2][1]-a[1][2]);

    return 0;
}

void fun(int a[][3]){
    ++a;//Ques 2
    a[1][1]++;
}
Run Code Online (Sandbox Code Playgroud)

第1行将抛出L值的错误,因为'a'是二维数组的名称.但是,对于第2行的情况,情况并没有发生.

谁能明白这个疑问?

c lvalue

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

为什么%在C中打印一半?

#include<stdio.h>
main()
{
printf("% % % %");
}
Run Code Online (Sandbox Code Playgroud)

对于上述程序,输出为%%.但为什么?(我用过gcc编译器).

c format-specifiers

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