How is a fixed array set? Without any cycles. I do this:

int A[100]=[34,9,22,4,10,2,0,0,0,10,9,9,8,5,3,8,3,4,13,20,8,0,26,0,20,30,7,26,7,20,15,8,17,3,17,3,1,16,1,12,13,35,7,4,6,51,6,12,16,10,0,2,12,9,10,33,11,18,0,3,14,1,24,4,17,12,6,8,7,6,18,1,7,11,14,38,19,48,5,4,0,4,29,23,3,1,37,9,36,46,2,23,12,8,1,8,9,8,0,16]; 

How to?

  • And working? - dzhioev
  • 2
    Because it is not Pascal, but Si. {} - karmadro4
  • 2
    An interesting approach to learning at random ... - Gorets
  • Pancake. Like 100500 different options tried before you write ... Thank you! - Magomed

1 answer 1

Enclose the contents of the array in braces.

 #include <stdio.h> int main () { int A[10] = {1,2,3}; int n = sizeof(A)/sizeof(A[0]), i; printf ("array A size = %d elements\n",n); for (i = 0; i < n; i++) printf ("A[%d] = %d\n",i,A[i]); int B[] = {10,20,30}; n = sizeof(B)/sizeof(B[0]); printf ("array B size = %d elements\n",n); for (i = 0; i < n; i++) printf ("B[%d] = %d\n",i,B[i]); return 0; } c:/Users/avp/src/cc/hashcode $ gcc ac c:/Users/avp/src/cc/hashcode $ ./a array A size = 10 elements A[0] = 1 A[1] = 2 A[2] = 3 A[3] = 0 A[4] = 0 A[5] = 0 A[6] = 0 A[7] = 0 A[8] = 0 A[9] = 0 array B size = 3 elements B[0] = 10 B[1] = 20 B[2] = 30 c:/Users/avp/src/cc/hashcode $ 

Initialized as written in initialization - the first three. For array B, the size is not specified, it is made equal to the number of initializers.