Random numbers in C

后端 未结 10 1400
栀梦
栀梦 2020-12-07 01:26
for(i = 0; i < n; i++){
        srand(time(NULL));
        printf(\"%d \", time(NULL));
        for(j = 0; j < (n-1); j++){
            a[i][j] = rand();
              


        
10条回答
  •  遥遥无期
    2020-12-07 02:00

    Sergey, you did not get an error message with the a[i,j] version simply because this is a perfectly valid expression. The comma operator evaluates the sub-expressions from left to right and returns the value of the last expression. Thus, writing a[i,j] is identical to a[j]. What you received in the print was the value of the pointer to the j-th vector in your matrix.

提交回复
热议问题