b) Explain the following definitions. For those that are illegal, explain what’s wrong and how to
correct it.
i) const long large;
ii) double salary = wage = 9999.99;
iii) int i = 3.14;
iv) short int big = 40000;
v) int a = b = c = d
i) const long large;
The definition is wrong because a constant variable must be initialized.
ii) double salary = wage = 9999.99;
The definition is wrong since wage was not declared.
iii) int i = 3.14;
The definition is wrong since an integer variable has been initialized with a floating point value.
iv) short int big = 40000;
The definition is correct.
v) int a = b = c = d
The definition is incorrect since the variables b,c,d were not declared.
Comments
Leave a comment