i want to know how to copy arrary without using any method
or function. I have tried the below
using System;
class e4
{
static void Main(string[] args)
{
int a,b;
int[ ] m= new int[5];
int[ ] n= new int[5];
for(a=0;a<=4;a++)
{
Console.WriteLine("enter any value");
m[a]=Convert.ToInt32(Console.ReadLine());
m[a]=n[a];
}
for(b=0;b<=4;b++)
{
Console.WriteLine(n[b]);
}
}
}
but it will give wrong result can anyone solve this problem



i want to know how to copy arrary without using any method or function. I have tried the below u..

Answer / jeremiah

It appears you are overwriting the value of m[a] with the
uninitialized version of n[a] (in .NET this will be
initialized to 0. So the output of your program will output
5 zeros instead of what you had input on the console.
Try changing your code to this (I formatted it slightly better):
-----------------------------------------------------------
using System;

class e4
{
static void Main(string[] args)
{
int a, b;
int[ ] m = new int[5];
int[ ] n = new int[5];

for( a = 0; a <= 4; a++ )
{
Console.WriteLine( "enter any value" );
m[a]=Convert.ToInt32( Console.ReadLine() );
// Don't overwrite m[a] here!
// m[a]=n[a];
n[a] = m[a];
}

for( b = 0; b <= 4; b++ )
{
Console.WriteLine( n[b] );
}
}
}
-----------------------------------------------------------

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More C++ General Interview Questions

a class that maintains a pointer to an object that is programatically accessible through the public interface is known as?

2 Answers   CTS,


What is runtime polymorphism in c++?

0 Answers  


What is exception handling? Does c++ support exception handling?

0 Answers  


Is std :: string immutable?

0 Answers  


Write a corrected statement in c++ so that the statement will work properly. if (x > 5); y = 2*x; else y += 3+x;

1 Answers  


What is prototype in c++ with example?

0 Answers  


what is object?

7 Answers  


What methods can be overridden in java?

0 Answers  


Explain rethrowing exceptions with an example?

0 Answers  


Explain mutable storage class specifier.

0 Answers  


What are the extraction and insertion operators in c++?

0 Answers  


What is the difference between a shallow copy and a deep copy?

3 Answers  


Categories