Q:

Explain the following definitions. For those that are illegal, explain what’s wrong and how to correct it

0

Explain the following definitions. For those that are illegal, explain what’s wrong and how to correct it.

(a) std::cin >> int input_value;
(b) int i = { 3.14 };
(c) double salary = wage = 9999.99;
(d) int i = 3.14;

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

#include <iostream>

int main () {
  // (a)
  //std::cin >> int input_value;  // Error: variable must be defined before using for input
  int input_value;
  std::cin >> input_value;

  // (b)
  //int i = { 3.14 };   // Error: loss information in list initialization
  double d = { 3.14 };  // OK
  double d2 = { 3 };    // OK

  // (c)
  //double salary = wage = 9999.99;  // Error
  double salary, wage;
  salary = wage = 9999.99;

  // (d)
  int i2 = 3.14;  // OK, `i2` is 3

  return 0;
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now