- #1
Lord Anoobis
- 131
- 22
Homework Statement
Assuming that
Code:
array1
Code:
array2
the contents of
Code:
array2
Code:
array1
Code:
array1 = array2;
Homework Equations
The Attempt at a Solution
This is a question I just saw in a book. As far as I can tell the given line doesn't work because the variables still need to be specified as arrays with [ ]. Anyway, I carried out a little experiment to see what happens when one tries something like this and I found...
Code:
#include <iostream>
int main ()
{
int array1[5], array2[] = {1, 2, 3, 4, 5};
array1[5] = array2[5];
for (int i = 0; i < 5; i++)
std::cout << array2[i] << "\t";
std::cout << std::endl;
for (int j = 0; j < 5; j++)
std::cout << array1[j] << "\t";
std::cout << std::endl;
return 0;
}
Code:
#include <iostream>
int main ()
{
int array2[] = {1, 2, 3, 4, 5};
int array1[] = {array2[5]};
for (int i = 0; i < 5; i++)
std::cout << array2[i] << "\t";
std::cout << std::endl;
for (int j = 0; j < 5; j++)
std::cout << array1[j] << "\t";
std::cout << std::endl;
return 0;
}
Code:
int array1[5] = {array2[5]}
Last edited: