Array Question

If there are 2 arrays named as test & sample with 20 integer elements in each of these declared as
int test[20],
sample[20],
then which of the following statement is wrong?
a)test=sample
b)sample=test
c)Both a & b
d)none of the above

Questions by Apra Kumar

Showing Answers 1 - 3 of 3 Answers

Manpriya Kaur

  • Aug 14th, 2011
 

Both a & b are wrong,,,,we can't assign arrays directly like this. this thing can only be applied on variables. further,to assign values of one array to another,we need to apply a for loop n assign values under each index separately.

  Was this answer useful?  Yes

Srinivas

  • Aug 15th, 2011
 

Both a and b are wrong.Option c is correct,Because int test[20] contains 20 elements with different address locations that are differ from int sample[20] addresses

  Was this answer useful?  Yes

rizwan

  • Aug 20th, 2011
 

In C# arrays are reference variables , so both a and b are correct

Code
  1.     static void Main(string[] args)

  2.         {

  3.             int[] a = new int[5];

  4.             int[] b = new int[5];

  5.             a[0] = 1;

  6.             b[0] = 2;

  7.             Console.WriteLine(a[0].ToString());

  8.             Console.WriteLine(b[0].ToString());

  9.             a = b;

  10.             Console.WriteLine(a[0].ToString());

  11.             b = a;

  12.             Console.WriteLine(b[0].ToString());

  13.             Console.ReadLine();

  14.  

  15.         }

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions