To add to the answer, I would like to point out that the variables are not initialized (in traditional sense). It is so called default initialization or, rather, a lack of initialization as the variables will be of whatever value that happened to be in the memory at that time.
To zero-initialize the array, you'll need to use the following syntax (that resembles calling a default constructor of an array)
struct Task{
int value, time, deadline;
bool operator < (const Task& t1) const {
return deadline < t1.deadline;
}
} task[1000]{};
...Well, it's simple in your case, since you don't have any user-declared constructors, but in other cases it may become tricky. Read this if you're interested value-initialization.
(And {}
is a new syntax for constructing objects introduced in C++11. The prior syntax ()
has several issues: it does not check that arguments are narrowed, and it suffers from the most vexing parse problem, when Foo aVariable(std::string("bar"));
is parsed as function declaration (see).)