1

As the title, is it possible to initialize a pointer in a struct to point to the first element of an array that is also in the same struct?

struct foo
{
    int barr[12];
    int* barr_itt;
};

struct foo f = {{0}, /*.?.*/} 
3
  • 1
    I'm curious about the application behind that question; syntactically, you now have a struct{int*,int*};. Commented Jan 13, 2015 at 16:55
  • yes, I have one pointer to itterate ofer the array, the other holds the location of the first element so it can be reset when it reaches the end. Commented Jan 13, 2015 at 16:56
  • 1
    wouldn't using barr[index % 12] achieve the same? Commented Jan 13, 2015 at 16:57

1 Answer 1

5

Yes, use the name of the variable

struct foo f = {{0}, f.barr} ;
Sign up to request clarification or add additional context in comments.

1 Comment

Well that should be easy, Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.