This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center
                            
                        
                    
                
                                6年前关闭。
            
                    
我有一本书的示例程序,在这段代码中有一行
++frequency[responses[RESPOSE_SIZE]];。我无法理解我们如何增加数组基地址?也许我是个傻瓜?但我仍然看不到那里的任何逻辑...请有人帮我....谢谢!

    int main()
    {
          int answer, rating;

           int frequency[FREQUENCY_SIZE] = {5};

           int responses[RESPOSE_SIZE] ={1,2,3,4,5,6,7,8,9,10,

                1,6,3,8,6,10,3,8,2,7,6,5,7,6,8,6,7,5,6,6,

                5,6,7,5,6,4,8,6,8,10};

       for(answer = 0; answer<RESPOSE_SIZE; answer++)
       {

          ++frequency[responses[RESPOSE_SIZE]];
       }

       printf( "%s%17s\n", "Rating", "Frequency" );

       for(rating=1; rating<FREQUENCY_SIZE; rating++)
       {
          printf( "%6d%17d\n", rating, frequency[ rating ] );

       }

        return 0;
    }

最佳答案

++frequency[responses[RESPOSE_SIZE]]并不意味着该数组的基地址增加。

这意味着数组frequency中从位置responses[RESPONSE_SIZE]开始的项目将递增。构造responses[RESPONSE_SIZE]是数组responses中位于位置RESPONSE_SIZE的项。

关于c - 无法理解此片段的某些部分? ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/15171908/

10-10 19:43