Q:

In the following code, determine the type of each variable and the value each variable has when the code finishes

0

In the following code, determine the type of each variable and the value each variable has when the code finishes:

int a = 3, b = 4;
decltype(a) c = a;
decltype((b)) d = a;
++c;
++d;

All Answers

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

#include <iostream>

int main() {
  int a = 3, b = 4;
  decltype(a) c = a;  // `c` is `int`
  decltype((b)) d = a;  // `d` is `int &` to a
  std::cout << a << " " << b << " " << c << " " << d << std::endl;  // 3 4 3 3
  ++c;
  std::cout << a << " " << b << " " << c << " " << d << std::endl;  // 3 4 4 3
  ++d;
  std::cout << a << " " << b << " " << c << " " << d << std::endl;  // 4 4 4 4

  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