fork download
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. int main()
  5. {
  6. std::vector<double>* data = new std::vector<double> {2, 4, 6, 8, 10, 12, 14, 16, 18, 20};
  7.  
  8. double a = (*data)[5];
  9. double sameA = data->at(5);
  10.  
  11. std::cout << a << ", " << sameA << std::endl;
  12.  
  13. // double b = *data[5]; // Invalid
  14.  
  15. double* c = &data->at(5);
  16. double* sameC = &data->at(5);
  17.  
  18. std::cout << c << ": " << *c << ", " << sameC << ": " << *sameC << std::endl;
  19.  
  20. //double* d = data[5]; // Invalid
  21.  
  22. delete data;
  23.  
  24. return 0;
  25. }
Success #stdin #stdout 0s 3460KB
stdin
Standard input is empty
stdout
12, 12
0x9c6aa48: 12, 0x9c6aa48: 12