222k views
5 votes
If you have the following variable declaration in your program,

const int SIZE=34;
then which of the following statements are legal?
a) SIZE ++;
b) x = SIZE--;
c) cout << SIZE;
d) cin >> SIZE;

User Seeker
by
8.0k points

1 Answer

2 votes

Final answer:

The only legal statement with the variable declaration const int SIZE=34; is c) cout << SIZE, as it simply outputs the constant's value. The other options attempt to modify the constant, which is not allowed.

Step-by-step explanation:

If you have the following variable declaration in your program, const int SIZE=34; then which of the following statements are legal?

  • SIZE ++; - This is illegal because SIZE is a constant and its value cannot be changed.
  • x = SIZE--; - This is illegal for the same reason; SIZE cannot be decremented.
  • cout << SIZE; - This is legal and correct. It prints the value of SIZE to the standard output.
  • cin >> SIZE; - This is illegal because you cannot change the value of a constant by reading into it.

Thus, the only legal statement among the ones listed is c) cout << SIZE.

User Eatonphil
by
8.3k points