{0}
Short C++ question
In the gametutorials, the
code stats to frequently appear. However, nobody bothers to explain what it does. What exactly does it do?
Would you mind giving an example of how it is used in the code? And possibly a link to the tutorial where it is used?
Qucik sample of the code:
Its for a bubble sort tutorial.
http://www.gametutorials.com/Tutorials/c++/Cpp_Pg6.htm
int num_array = {0};
Its for a bubble sort tutorial.
http://www.gametutorials.com/Tutorials/c++/Cpp_Pg6.htm
It could be for initializing an integer array of length 1.
Something like :
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...
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...
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 ....
and it will put those numbers into their place in the array.
Does that make sense?
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?
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, 0int array[3] = {0}; // elements are 0, 0, 0
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement