Sign in to follow this  

Short C++ question

This topic is 4761 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

It could be for initializing an integer array of length 1.
Something like :

int dummy[1] = {0};

// same as...
int dummy[1];
dummy[0] = 0;



Otherwise, it should not compile just like this.
I guess 0 would be evaluated as 'false', but it needs a semi-colon ';' right after it.

I hope it all makes sence...

Share this post


Link to post
Share on other sites
It creates an array with 'i' numbers, and it initialises the array with the data that is in the curly brackets ..

so ... you can do the following ....

int num_array[3] = {1,4,7};


and it will put those numbers into their place in the array.

Does that make sense?

Share this post


Link to post
Share on other sites
One uses the curly brace notation to initialise arrays. There needs to be atleast one element specified within the braces, the remaining array elements of type T to be initialised are initialised with the value T()...

int array[3] = {0, 2}; // elements are 0, 2, 0
int array[3] = {0}; // elements are 0, 0, 0

Share this post


Link to post
Share on other sites

This topic is 4761 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this