A question about two dimensional arrays in C How to tell if all the numbers in an array are 1

Updated on technology 2024-03-22
12 answers
  1. Anonymous users2024-02-07

    One-dimensional arrays hold the same values, but in the case of matrices, determinants.

    and other types, it is more convenient to use two-dimensional ones. As for the character array, it just means that the elements stored in it are characters.

    Note that the 1,2,3 in ,} has {}, which means that the first element in each line is 1, 2, 3The remaining elements such as a[1[2], a[2][2], etc., are defaulted to 0. And b[3][3]=This is only one {}, which encloses 4, 5, and 6.

    It means that b[0][0], b[0][1], b[0][2] are 4, 5, 6The rest are all 0.

    strcat(s1,s2) is the second string.

    Copy it after the first string and spell it into a string. Once the copy is complete, the function is added'\0'to indicate the end of the string. Therefore, after strcat(s1,s2), the actual result is 123abcde 0

    Take the length with strlen, and it will naturally be 8.

  2. Anonymous users2024-02-06

    The most straightforward way to do this is to call the function, pass the array as an argument, and then define a variable flag as a flag in the function to iterate through the two-dimensional array in a loop.

    If the array element is 1, set the flag to 1 to continue scanning, otherwise set it to 0 and exit the loop.

    If the flag is 1, it means that all the array elements are 1, otherwise it is not all 1

  3. Anonymous users2024-02-05

    Because in C, the essence of the array name is the first address of the array. A sentence that calls the trmul function in the main function.

    trmul(a,b,4,5,3,c);

    means that the array a

    The first address of bc is given as a parameter to the function.

    voidtrmul(

    a,b,m,n,k,c)

    intm,n,k;

    double

    a,b,c;Ab here

    c up. Let's take the first array as an example:

    In the main function, a is a two-digit array name, and a is the first address of a two-digit array with 20 elements, trmul(a,b,4,5,3,c) when the function is called;

    The value of a (the first address of the 20 elements) is given to the corresponding form argument as the argument of the function.

    voidtrmul(

    a,b,m,n,k,c)

    intm,n,k;

    double

    a,b,c;

    Here's a lot. Because a in the subfunction is a one-dimensional array name (essentially a pointer variable.

    The array name is still the first address of the array) so the 20 elements in the main function are a one-dimensional array with 20 elements from the perspective of the subfunction, and of course they can also be seen as elements with 4 rows and 5 columns.

    Hope it helps.

  4. Anonymous users2024-02-04

    A symbolic constant is a constant represented by an identifier, and a one-dimensional array is defined as follows: type specifier + array name + [constant expression];

    A type specifier is either a basic data type or a constructed data type. An array name is a user-defined array identifier. The constant expression in square brackets indicates the number or length of the array elements, which can be constants or symbolic constants, and cannot be variables.

    For example: 1, int x[8]; Indicates that an integer array x is defined, and the length of the array is 8

    2、float a[8],b[10];This means that you define a solid array b with a length of 8 and a solid array c with an array length of 10

    3、 ch[15];Indicates that an array of characters is defined ch, and the length of the array is 15.

  5. Anonymous users2024-02-03

    *(s+i), because he is a one-dimensional array since, the first address of the array of s tables, s+i, represents the first address of element i, so du is s[i], and s[i] is of course the value.

    But zhi *(a+n)+m, where a, is a 2-dimensional array dao, *(a+n) represents a[n], you say a[n] can it be a value for a two-dimensional array, it must be the first address of the n+1 line, +m, add and add m, the address of *(a+n) here is equivalent to the above s, plus m, which is equivalent to the above plus i, so he is the address of a[n][m].

    Saying that it's a two-dimensional array, the first * can only indicate which line you are in, and the second * is needed to find the specific value.

    It is equivalent to, I asked you to go to room 4 on the fifth floor to give me things, but I only gave you the key to the stairwell on the 5th floor, and you go in and stand in front of door 4, and you can't get anything. The key to Door 4 is required.

  6. Anonymous users2024-02-02

    *(*w+1)) should be w[1][0], as for the later writing, there is no need to be entangled, just write it as you can understand. For example, *(w[1]+4) or *(*w+1)+4) means w[1][4].

  7. Anonymous users2024-02-01

    The name of the two-dimensional array is the pointer (constant pointer) of the one-dimensional array of specified length, and the one-dimensional array itself is a pointer, so it is generally called the pointer of the pointer, but there are actually differences.

    The type of w is int (*5).

    *(w+1)) is equivalent to w[1][0], who told you that it wasn't? If you doubt yourself, a test is not over.

    w+1 is equivalent to &w[1] or w[1], and type int (*5) is the same as w.

    w+1) is equivalent to &w[1][0], type int * Note that w+1 and * (w+1) addresses are the same but of different type.

    *(w+1)) is equivalent to w[1][0].

    w+1) is the address on the second line, the type is int *, it is a whole, and it must be used as a one-dimensional array read with parentheses.

    The correct way to write it is: (*w+1))[4].

    If you don't have parentheses, it doesn't mean the same thing, *(w+1)[4] becomes the fifth element in the second line as a pointer, but in fact the element is an integer, which can cause illegal address access.

  8. Anonymous users2024-01-31

    Yes, a two-dimensional array is originally regarded as a special one-dimensional array, the length of this one-dimensional array is the number of rows of the original two-dimensional array, and each row of the original two-dimensional array is an element of the special one-dimensional array, but the elements of this special one-dimensional array are not actual elements, they have other meanings, please see the following figure:

    In fact, a[0] and a[1] are two pointers, pointing to a[0][0] and a[1][0], respectively, and a is an array name with two elements, a[0] and a[1], which points to a[0], that is, a is a pointer to a pointer, that is, a second-level pointer. This makes it possible to make an indirect access to this particular one-dimensional array: *(a[i]+j).

    In addition, a[i][j] is direct access; *(a+i)+j) is a secondary indirect visit.

  9. Anonymous users2024-01-30

    The memory in a computer is one-dimensional, so everything should be one-dimensional.

    Two-dimensional or even three-dimensional arrays are artificially built data structures that are easy for developers to understand and think about, and their essence is still one-dimensional.

  10. Anonymous users2024-01-29

    A few dimensions can be considered as a matrix. a[2][3] is a matrix with two rows and three columns. This is the "shape" of the data.

    An array of characters means that the data in this array is a "type" of data that is "characters". Type and shape are two different things. Of course, a[x][y] actually refers to an array a[x], with y elements in x.

    If understood in terms of matrix, then.

    a[3][3]=|1][0],[1][1],[1][2]|- When defined, a[x][3]=, where {} in "" is the combination of all the elements in a row, that is, it represents all the data in the first row of the matrix, because there is only one, and there is no specific indication that the data is filled from left to right, so a[0][0]=1.

    Because there is only one {}, there is no special indication when filling the data, so the data in {} will be populated by the number of 3 data per row, if there are 4 digits in {} when defining b, the 4th number will be populated in b[1][0].

    strcat and strlen themselves baidu go, library functions.

  11. Anonymous users2024-01-28

    One-dimensional arrays store the same values, but if it is a matrix, determinant, etc., it is more convenient to use a two-dimensional one. As for the character array, it just means that the elements stored in it are characters.

    Note that the 1,2,3 in ,} has {}, which means that the first element in each line is 1, 2, 3The remaining elements such as a[1[2], a[2][2], etc., are defaulted to 0. And b[3][3]=This is only one {}, which encloses 4, 5, and 6.

    It means that b[0][0], b[0][1], b[0][2] are 4, 5, 6The rest are all 0.

    strcat(s1,s2) is to copy the second string after the first string and spell it into a string. Once the copy is complete, the function is added'\0'to indicate the end of the string. Therefore, after strcat(s1,s2), the actual result is 123abcde 0

    Take the length with strlen, and it will naturally be 8.

  12. Anonymous users2024-01-27

    Problem 1: In fact, there is no need to have a two-dimensional array, and the character array can store characters.

    Problem 2: The assignment result of a is a[0][0]=1, a[1][0]=2, a[2][0]=3, and the rest is 0, if you do not write curly braces, then assign b[0][0]=4, b[0][1]=5, b[0][2]=6, and write curly braces, each curly brace represents a row.

    Problem 3: The strcat function is used to connect two strings1 and s2, and strlen is used to calculate the length of the string (excluding the ending "0").

Related questions
8 answers2024-03-22

According to the judgment conditions.

if(d>0)b=c; >>>More

6 answers2024-03-22

The p of both is a pointer.

p=&t, change the content that p points to to the address of t, and p=&t is the address that changes the pointer to t. >>>More

5 answers2024-03-22

bool f=0;

for(int i=1000;i>=1;i--) Start with the largest number of 1000 and try to the smaller number. >>>More

8 answers2024-03-22

It's nonsense to say so much above. Landlord please see: pay attention to your program: printf("%d,%d",(a,b),(b,a); >>>More

15 answers2024-03-22

ints need to be expressed according to the size of the compiler. >>>More