What are the different ways to assign values to arrays in the C language?
C语言给数组赋值的形式有以下几种:
- Assign values one by one: You can assign values to individual elements by index, for example: array[0] = 1; array[1] = 2; array[2] = 3;…
- Assigning values using loops: You can use loop statements (such as a for loop) to assign values to arrays, for example: for(int i=0; i
- Initialization assignment: you can assign values to the array at the same time as defining it, for example: int array[] = {1, 2, 3, 4, 5};
- String assignment: For character arrays, assignment can be done through string assignment, for example: char str[] = “Hello World”;
- To copy values from one array to another, you can use the memcpy() function in C, like this: memcpy(dest, src, length*sizeof(int));