About the dp array

why haven’t we passed the array by reference? in c++ are arrays passed by reference by default ?

hello @Senjuti256

arrays are always passed by pointer . i,e whenever we pass any array then only its base address is passed.

read difference b/w pass by pointer ,pass by refrence (yeah pointer and refrence are different in c++) , pass by value

From gfg? Or somewhere else?

yeah u can read from gfg

I read it but they have mentioned nothing for array. When to use which and why?

in case of array we dont have any option .
it will be always pass by pointer.
due to which whatever chnages u will make on passed array inside any function it will be reflected on original array.

for variables and objects we have other option has well.
pass by value will just create a copy of passed variable/object so changes made on copy will not reflected on original variable/object.

behaviour of pass by refrence and pointer is same . they make changes on same original variable /object

but we pass vector by reference and not by pointer right?

vector is class and we make its object na.

Why can’t we pass array by reference?

Oo now I understand vectors list stacks etc all are objects of their respective classes so can be passed by reference also right?

Can we pass array by value?

no it is ALWAYS passed as pointer (in c++).

yeah correct

When can an array be passed as a pointer like we write int* a where a is an array? Is it when the array is dynamically allocated?

@Senjuti256
in both the cases it will be pointer
either u declare ur array as fun(int a[]) or fun(int *a) both are same

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.