The problem of structs in the C language, the understanding of constructs in the C language

Updated on technology 2024-04-08
6 answers
  1. Anonymous users2024-02-07

    It seems that you don't know much about structs and struct pointers, the data array is a struct array that you define, it consists of two knot body elements, and each struct element contains two members x and y, the first element is 1 and 10, the second element is 2 and 20, the struct pointer p you defined starts to point to the first element of the array data, p points to the second element of the data array, and the pointer p can manipulate the two members x and y

    In the beginning: p->x is 1

    p->y is 10

    p pointer plus 1 to move to the second element of the array:

    p->x is 2

    P->y is 20

    Do you understand?

  2. Anonymous users2024-02-06

    p=data, where p points to 1

    p->y points to the next one of 1, i.e. 10

    p->x points to 2 after p-x

    p->y after p points to 20

  3. Anonymous users2024-02-05

    That is true. struct st *p=data;First, assign the first address of the array to p;

    But p is of type struct and has two integer variables, so p thinks that the two integer variables 1 and 10 belong to it, so the value of p->y is 10

    In the second statement, it should be clear that p++ is the number of bytes occupied by the type of struct st, first of all, st is a struct type with two int variables, so after ++p, the point of p must be moved back by the size of the number of two int types, where p points to 2, so (++p)->x is equal to 2

    If you still don't feel detailed enough and not clear enough, you can send me a message.

  4. Anonymous users2024-02-04

    Define the struct variable st, and define the struct variable array data;

    struct st

    int x,y;

    data[2]=;

    main()

    struct st *p=data;A pointer that defines a struct variable, pointing to an array.

    printf("%d",p->y);

    printf("%d",(+p)->x);(++p) points to the second struct element of the array.

    It can be understood that there are two elements in the array data.

    The defined pointer p is structural, so ++p is already pointing.

  5. Anonymous users2024-02-03

    struct st

    int x,y;} data[2]=;means data[0]=, i.e. data[0].x=1,data[.y=10.

    So *p=data[0]. p->y = 10;

    When you increment pointer p by 1, the pointer moves to data[1] (not to 10). Each move is a move of the whole. So (++p)->x=2.

  6. Anonymous users2024-02-02

    1. Definition of structureA struct is a collection of one or more pieces of data, which can be of different types, and the struct is equivalent toarrayupgrades. If we want to count the grades of students in a class, and the grades are of the float type, we can use the gradesarrayDeposit. However, if you want to count the name, gender, and grades of students in a class, the name is a string, the age is an integer, and the grade is a decimal, because the data type is different, it obviously cannot be usedarrayDeposit.

    To solve this problem, another type of construct data is given in C - struct. It can store multiple data types of the same object together.

    2. Definition formWay 1, place the struct variable directly at the tail end of the struct.

    struct structure name; Zhang San male scored 100Fourth, the use of structureTake the example of Mode 2 as an example.

    struct student ;Zhang San Male Score 100*** Use***

    zhangsan. score =60;Assign Zhang San's score to 60

Related questions
4 answers2024-04-08

I've seen questions like this, and I don't understand what you mean, but I think it's like this, structab; I hit ... where you can add definitions of all data forms, e.g., int >>>More

6 answers2024-04-08

Define the struct:

typedef struct _legaladdress_{ >>>More

8 answers2024-04-08

The semicolon is the sign of the end of the statement, but the semicolon is not used after the loop, if, and subfunctions such as long long a (int b), and everything else is used, but two semicolons cannot be added, although it will not cause an error, but it may affect the result.

7 answers2024-04-08

The first if(!) a) means that if a is equal to zero, take x -- the second and third means that if b and c are not 0, it is executed. >>>More

11 answers2024-04-08

Valid variable names for the C language:

First, it can only contain numbers, letters, and underscores. >>>More