c Answer to the exercise

Updated on educate 2024-04-09
4 answers
  1. Anonymous users2024-02-07

    c is defined outside of class, so it is a global variable. A is a private variable defined in class a.

    Here c is a global variable, b is a static variable (static), and a is a normal variable. b is initialized to 0

    These set functions are to add 1 to the corresponding variable

    A, B, and C in A1 are 1 0 0, respectively

    a1 1 1 0

    a1 1 1 1

    A, B, and C in A2 are 1 1 1 respectively (B is static and remains 1).

    a2 1 2 1

    a2 1 2 2

    So; Output 1 2 2

    while(at is a variable that temporarily saves values t=a; a=b;b=t;It's a and B swapped.

    c -- is c minus 1

    The program runs the first while judgment a and then a, b, and c become a=2, b=1, c=1

    The second while judgment a then a, b, c becomes a=1, b=2 , c=0

    The third while judgment a outputs the values of a,b,c 1,2,0

    str is the name of the array, which is a pointer to the head of the array.

    str+2 is the position of the last two characters at the beginning of the array str, so the z is covered.

    The end result str is xyabcabc

    Alas......These questions are the most annoying for the examiners.

  2. Anonymous users2024-02-06

    1.A is defined inside the class, C is defined outside the class!! A is the class name, A1, A2 objects, is the call of the function!!

    2.If while(a is the third character in str!)

  3. Anonymous users2024-02-05

    I'm also a beginner, so maybe there's something wrong with what I've said, for reference!

    1.The variables in the class will be added with a this pointer, and a will become this ->a, and c is not in the class a, so this pointer is not added (this pointer will be automatically passed in when called, without manual intervention).

    Then, b is a static property, which does not belong to a particular object, and belongs to the class a, int a::b=0; This sentence opened up memory space for him and initialized it, and then the two setb operations were the same B.

    As for those formulas, they call the methods in the A1 object and the A2 object.

    a::b = 1c = 1

    a::b = 2

    c = 22.The problem lies in Aa = 2 b = 1 c = 1 a < b the result is false i.e. 0, 0 < c the result is true, continue.

    a = 1 b = 2 c = 0 a < b the result is true i.e. 1, 1 < c the result is false, end.

    The pointer is useful because you can add or subtract it directly, and +1 will move to the next one (regardless of the type), such as int a[10], a points to a[0], a + 1 points to a[1], a + 2 points to a[2], and the same goes for char arrays, str points to str[0], str + 2 points to str[2].

    Attention, str + 2 is an address!

  4. Anonymous users2024-02-04

    Q1: First of all, it is clear that a is defined in class a, which is an ordinary variable. c is defined outside of the function so it is a global variable, it does not belong to any function, it belongs to a source program file. Its scope is the entire source program.

    Secondly, the main function first defines the two objects A1 and B1 in class A, and then accesses the member functions in the class objects in turn. Get a=1;

    Get b=1;c=1;

    Get a=1;(Because there is int a::b=0; b is a local variable acting on class a, so the initial b = 1 in a2 and the initialization of a in a2 is 0; c is a global variable, c=1).

    Get b=2;c=2;

    Hence the output 1 2 22 q.

Related questions
30 answers2024-04-09

1.Type B (9+9) (4-1) = 6 yuan.

Class A 6 * 4 = 24 yuan. >>>More

4 answers2024-04-09

Summary. Methods of changing general interrogative sentences: (one tone, two changes, three question marks). >>>More

9 answers2024-04-09

It's hard to say, it's convenient for smart brains to learn mathematics by themselves, and the more they learn, the more interested they are; But IQ generally learns a lot of mathematics, memorizing * formulas and theorems * is a must, mathematics is often easy to ignore the subject * textbooks, especially in high school, under the premise of a solid foundation, * the amount of questions must also be accumulated to a certain extent, because the questions are too much, you can be proficient in using the learned formulas and theorems, diligent thinking is a must, if you turn the answer every time you encounter a problem, even if you remember the next encounter or will forget. >>>More

16 answers2024-04-09

a^2=ab^3=c

b*d=d10b+a)*e=100a+10d+e(10a+b)*(10c+e)=? >>>More

9 answers2024-04-09

By definition, there is (sinx).'=lim[sin(x+ x)-sinx] ( x), where x 0, will sin(x+ x)-sinx, that is, sinxcos x+cosxsin x-sinx, since x 0, so cos x 1, thus sinxcos x+cosxsin x-sinx cosxsin x, then (sinx)'=lim(cosxsin x) x, here an important limit must be used, when x 0, lim( sin x) x=1, then (sinx)'=cosx. >>>More