Q:

Determine the types and values of each of the following variables

0

Determine the types and values of each of the following variables.

(a) int* ip, &r = ip;
(b) int i, *ip = 0;
(c) int* ip, ip2;

All Answers

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

#include <iostream>

int main() {
  {
    int* ip, i, &r = i;  // `ip` is `int *`, `i` is `int`, `r` is `int &`
    std::cout << "(a)" << std::endl;
    std::cout << "ip\t" << typeid(ip).name() << std::endl;
    std::cout << "i\t" << typeid(i).name() << std::endl;
    std::cout << "r\t" << typeid(r).name() << std::endl;
    // Note that `typeid` will lose the `const` qualifier and reference
  }
  {
    int i, *ip = 0;  // `i` is `int`, `ip` is `int *`
    std::cout << "(b)" << std::endl;
    std::cout << "i\t" << typeid(i).name() << std::endl;
    std::cout << "ip\t" << typeid(ip).name() << std::endl;
  }
  {
    int* ip, ip2;  // `ip` is `int *`, `ip2` is `int`
    std::cout << "(c)" << std::endl;
    std::cout << "ip\t" << typeid(ip).name() << std::endl;
    std::cout << "ip2\t" << typeid(ip2).name() << std::endl;
  }

  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