Structure without structure name

The structure defined below does not have a structure name. Moreover, I cannot get part of the array. Thanks in advance. What do the values ​​in the structure array mean?

#include <stdio.h>
int main()
{
    struct
    {
        int x,y;
    } s[] = {10,20,15,25,8,75,6,2};
    int *i;
    i = s;

    clrscr();
    printf("%d\n",*(i+3));
    return 0;
}
+3
source share
5 answers

Now we have a question that can be answered:

struct
{
    int x,y;
} s[] = {10,20,15,25,8,75,6,2};

Declares an array with the name of sanonymous structures. Each structure has two fields int. The size of the array is not specified, so it will be as large as for storing the list of initializers (the "list of initializers" is the technical term for the list of numbers enclosed in a brace after the equal sign).

; ; , . , :

struct
{
    int x,y;
} s[] = { {10,20}, {15,25}, {8,75}, {6,2} };

, , s. x y. , :

s[0].x == 10
s[0].y == 20
s[1].x == 15
s[1].y == 25

..

+8

, struct , , .

C

struct{
/*
.
.your structure members
.
*/
}<variable name>;

s -

struct 
   {
      int x,y;
   }
+4

, , . "25", , . , , "" , , . :

struct
{
    int x;
    char y;
} s[] = {10,20,15,25,8,75,6,2};

, ? : " ". , ? char . 8 , . ANSI C C99 char :

", char, .

, "" . , , , , . . , . :

#include    <stdio.h>

int main()
{
    struct
    {
        int x, y;
    } *ps, s[] = { {10, 20}, {5, 25}, {8, 75}, {6, 2} };

    ps = s;

    printf( "%d\n", *(ps + 3) );
    printf( "%d\n", s[3].x );
    printf( "%d\n", (ps + 3)->x );

    return 0;
}

ps . ps = s, ps . 1 ps, ps += 1;, . , printf 6. , ? *(ps + 3), ps, , . s[3].x s x . , (ps + 3)->x, ps, , , x.

, s. , . , , , -, , .

+3

, , , . s , .

, .

+2

   struct mystructTag
   {
      int x,y;
   }mystruct;
   mystructTag mystructlist[]={ {10,20}, {15,25}, {8,75}, {6,2} };

blooper!

+2

Source: https://habr.com/ru/post/1762894/


All Articles