How to assign to array?
-
As follows:
int arr[], brr[];
arr = brr; //error: cannot assign one array to another,
//and I have a question, Why can't, but other language(i.e java,C#) can do that?so, how to do that assign one array to another?
-
As follows:
int arr[], brr[];
arr = brr; //error: cannot assign one array to another,
//and I have a question, Why can't, but other language(i.e java,C#) can do that?so, how to do that assign one array to another?
Use: int*arr=&brr;
-
Use: int*arr=&brr;
That may not accomplish what he wants. If he's making a temporary copy to use as a scratch pad in a calculation and wants to preserve the original, it certainly won't. Your example just provides a different way to access the same data, not a copy.
You measure democracy by the freedom it gives its dissidents, not the freedom it gives its assimilated conformists.
-
As follows:
int arr[], brr[];
arr = brr; //error: cannot assign one array to another,
//and I have a question, Why can't, but other language(i.e java,C#) can do that?so, how to do that assign one array to another?
For copying arrays, you can use functions like memcpy_s[^] and CopyMemory[^]. These functions require you to know the size of the array. In C++, ideally you should be using the STL containers like
vector
,list
etc. and then you can use the copy[^] function to make a copy of a container using iterators as shown in the example in the documentation.«_Superman_» I love work. It gives me something to do between weekends.
Microsoft MVP (Visual C++)