CPharderthanDarkSouls's blog

By CPharderthanDarkSouls, history, 5 years 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

| Write comment?
»
5 years ago, # |
  Vote: I like it +1 Vote: I do not like it

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

»
5 years 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++.

»
5 years 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.