hello every one i want to ask that i have read that we can declare dynamic array only by using pointer and using malloc or newlike
int * array = new int[strl
What you have is called a variable-length array (VLA), and it is not part of C++, although it is part of C99. Many compilers offer this feature as an extension.
Even the very new C++11 doesn't include VLAs, as the entire concept doesn't fit well into the advanced type system of C++11 (e.g. what is decltype(array)
?), and C++ offers out-of-the box library solutions for runtime-sized arrays that are much more powerful (like std::vector
).
In GCC, compiling with -std=c++98/c++03/c++0x
and -pedantic
will give you a warning.