CPharderthanDarkSouls's blog

By CPharderthanDarkSouls, history, 19 months ago, In English

In a program if i use /* int *a = new int [n] / (and using delete at the end), the compiler throws sigbart error but if i use / int a[n] */ it compiles successfully ,Why ?

program : https://ideone.com/e.js/lZfJuL

 
 
 
 
  • Vote: I like it
  • +10
  • Vote: I do not like it

»
19 months ago, # |
  Vote: I like it +1 Vote: I do not like it

True statement is : typename name[size of array];

»
19 months ago, # |
  Vote: I like it 0 Vote: I do not like it

If anyone knows the reason, I would also like to know. I have also faced this problem many times. Nowadays, I am using vector everywhere to prevent all array shit in c++.

  • »
    »
    19 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Is there a reason to use manual dynamic memory allocation (as in not the standard containers which handle that for you) at all in competition programming?

»
19 months ago, # |
  Vote: I like it +6 Vote: I do not like it

If you use new[] to allocate memory, you must use delete[] (not delete) to free it.