0

On hackerrank I came across a question which contained this piece of code

int main(){

    int n, val;
    cin>>n; //The number of objects that is going to be created.
    Person *per[n];
    ...

I thought it wasn't possible to have dynamically sized arrays in C++ so I'm pretty confused about this and would appreciate any clarification.

Sentinel
  • 441
  • 1
  • 6
  • 25
  • 3
    Yeah there are compilers like GCC that support VLA's. That's not c++ standard though. – πάντα ῥεῖ May 30 '17 at 00:55
  • 3
    And please stay away from online code judge engines like _hackerrank_. You'll learn nothing that's really relevant for professional c++ programming. – πάντα ῥεῖ May 30 '17 at 00:58
  • What would you suggest instead? I just want to prepare myself for coding interviews which don't necessarily reflect what actual programming is like. – Sentinel May 30 '17 at 01:17
  • The usual and best practice is to use a `std::vector` instead. Raw c-style arrays aren't really a good way to go anyways. – πάντα ῥεῖ May 30 '17 at 01:20
  • _"for coding interviews which don't necessarily reflect what actual programming is like."_ Just surprise them. If you can't, the company is probably doing shit, and you don't want to attend there. I personally won't attend any company which is annoying me with stupid apprentice tests anyway BTW. I'd just leave the interview immediately. – πάντα ῥεῖ May 30 '17 at 01:22

0 Answers0