-5
struct point
{int X, Y;} a[4], b[4];

I found this piece of code on some program that works and I don't understand how this works and I can't find anything about how it works?

Can anyone explain it please?

  • 2
    That piece of code is not valid C++ as there are no `Struct` and `Int` keywords in C++. – Ron Jan 16 '18 at 12:18
  • 2
    I would suggest one of these to help you https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list – UKMonkey Jan 16 '18 at 12:19
  • Is the choice of upper/lower chars in the code sample an accident? As @Ron pointed out correctly: `Struct point { Int X, Y; } a[4], b[4];` (as is) is not correct code. `struct point { int X, Y; } a[4], b[4];` would be. The latter defines a `struct`, named `point` with two components (`X` and `Y`) of type `int` and declares two instances (`a` and `b`) of the just defined `struct point` which are both arrays with 4 elements. – Scheff's Cat Jan 16 '18 at 12:24
  • @Scheff -- yes, it's an accident. Some devices are too smart to be useful; they insist that when you type `struct` at the beginning of a line you meant to type `Struct`. – Pete Becker Jan 16 '18 at 12:51
  • After you edited your question, it turns out that the answer of Some Programmer Dude is correct. So, you may [accept](https://stackoverflow.com/help/someone-answers) it to "pay" for his effort. – Scheff's Cat Jan 16 '18 at 12:58

2 Answers2

9

That is the same as

struct point
{
    int X, Y;
};

point a[4];
point b[4];

In other words, you define a structure (named point) and then declare two variables a and b, both being arrays of four elements of the structure.

Some programmer dude
  • 400,186
  • 35
  • 402
  • 621
0

It is array of structure which can store 4 element of structure type for exampme x[0].a=10 and x[0].b=20....till x[3].

Rohit
  • 142
  • 8