c Arrays

Updated on technology 2024-05-07
5 answers
  1. Anonymous users2024-02-09

    First of all, make sure that the b in the program is correctly assigned to the value you entered, and use printf to type it out.

    Then, if(b!= sh[a]) is problematic.

    The value of a should be 10 at the end of the loop. In C++, the array index starts at 0, and the tenth subscript in the array is 9. In this case, the content accessed by using sh[a] has actually exceeded the array boundary, which is called out-of-bounds.

    c What is accessed out of bounds in a C++ program is uncertain. For a definition of cross-border access, please refer to the C++ language for details. There are many principles and contents, so I will not describe them one by one here.

  2. Anonymous users2024-02-08

    Your mistake is that the value of sh[a] has been set to 10 after the loop, so the error will occur, and the following is the modified program that can be debugged to run the result correctly.

    #include

    main()

    int i,b,a[10];

    scanf("%d",&b);

    for(i=0;i<10;i++)

    a[i]=i+1;

    if(a[b-1]==b)

    printf("Equal");

    elseprintf("Not equal");

  3. Anonymous users2024-02-07

    Your **:

    if(b!=sh[a])

    printf("Not equal");

    elseprintf("Equal");

    The meaning is: when b is not equal to 10, print "not equal" and press enter, other, print "equal" and press enter.

    I don't want to teach you how to change it.

    And if you just want to implement "if the input number is equal to 1 10, it will show that it is equal to, and if it is not equal to, it will show that it is not equal to", you don't need an array at all, as long as you define a variable of type int, such as i, and then do the loop.

    I won't give you the specifics, think about it yourself.

    In fact, you can do this, first round the number you entered, and then compare the size, such as b=b%1, and then, when sh[0]=

  4. Anonymous users2024-02-06

    It turns out that it is C, not C++.

    const size_t arr_sz = 10;

    int arr[arr_sz],num(0),flag(0);

    num)arr[sz++]= (int)sz + 1;

    if (num != arr[sz])

    flag = 1;mark, 0 equal, 1 unequal.

    break;

    if (flag == 0)

    count <<"Equal" count <<"Waiting"<

  5. Anonymous users2024-02-05

    After the array is initialized in a loop, the value of a becomes 10, and sh[10] is of course not equal to b.

Related questions
7 answers2024-05-07

In the whole main function, only this one variable, whether it is the first for or the second for, is the same i, the second for will have i=-1, in the case of i= -1, and printf("%d ",a[i]);Statement. So fear not! When there is no second for the case: >>>More

8 answers2024-05-07

2D array address - > row address - > column address (variable address) - > variable value, or excerpt a description for you. >>>More

3 answers2024-05-07

Heada and headb are both singly linked lists with leading nodes. In this algorithm, we delete the common elements from the ith element in the heada linked list, and then insert the single-linked list heada before the jth element of the headb. >>>More

7 answers2024-05-07

I think lz just wants to print out the address of a and the address of a+1 Here, a is the starting address of the array, so &a takes the address with a as a variable, that is, the address that stores the address of the array, but if (a+1) is addressed, it is not right, because (a+1) is not a defined variable here, but the value of a temporary variable, it is only equal to the value of the next address of the starting address of the array, not a variable that stores the value, and it is not right to take the address. >>>More