Question about structs

I am reading about classes and structs and different ways to use them.
In one example, I have seen this kind of declaration:
1
2
3
4
5
6
7
8
9
10
11
struct test 
{
   int val;
};

int main()
{
   int a[5];
   struct test *s = (struct test*)a;
   s->val = 10;
}


What kind of initiation of *s is this? Are we casting a struct to an integer array? I am from the world of Java and have not seen anything like this before.

Could someone please explain what is really happening in the code.

closed account (zb0S216C)
I might be wrong here but it looks like this code is casting a to a pointer that points to an instance test.

Wazzak
Topic archived. No new replies allowed.