I'd like to know which is faster and when to use:
this (int type is just an example I mean it generally):
int* ptr = new int (123);
int* arr = new int [];
and this:
int num = 123;
int arr [];
Well I know that the first are pointers and the second are references.
...
There are several terminological mistakes in your question, which makes it hard
to understand, but it appears that you want to know when to use dynamic memory
as opposed to automatic (or static) memory (i.e. when to create objects with
'new' as opposed to defining them directly in local (or namespace) scope).
The rule of the thumb is: use dynamic memory when you really have to; use
automatic (or, much less often, static) memory in all other cases. The reasons
for using dynamic memory usually include situation when
1. it is necessary to have an object who's lifetime is different from
the one imposed by the rules of static or automatic storage duration (by scope,
etc.)
2. the type of the object referenced by a pointer (or a reference) is
not known at compile time (such as concrete size of an array or dynamic
type of a polymorphic object)
3. the total number of concrete objects of certain type is not known at
compile time (such as linked list nodes or tree nodes)
4. the object is to large to be placed in automatic or static memory
Dynamically allocated objects are theoretically slower to access, but in
practice the difference in access speed is more than negligible on modern
hardware platforms. Although it is worth noting that thoughtless use of dynamic
memory might lead to heap fragmentation and cache-unfriendly data layout, which
might have noticeable negative impact on program's performance.