2

i searched for my problem, but didn't found it.

I have a declaration of an pointer array

int *Blocks[] = {Block1,Block2,Block3,Block4};

The Blocks are arrays with a length of 50.

Now i have a for-loop, there i want to step by step init the fields

for(int i=0;i<50;++i)
{
*(Blocks[section])+i = 1;
}

The One should be a variable later. Is it right or whats the right expression to get the array field of the selected section?

Thanks to every answer

3 Answers 3

4

No, that line isn't quite right. The following is (note the position of the parentheses):

*(Blocks[section]+i) = 1;

or, equivalently but more concisely:

Blocks[section][i] = 1;
Sign up to request clarification or add additional context in comments.

Comments

2

What you wrote almost works, you can do:

*(Blocks[section] + i) = 1;

But the best solution would be to use C's syntactic sugar and write:

Blocks[section][i] = 1;

1 Comment

thank you both! Blocks[section][i] = 1; is what i've searched for
-1

you may set init that fields as

*(Blocks[section]+i) = 1;

and maybe you should malloc enough memory before you init Blocks

Comments

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.