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

Is main a class in c++?

0 Answers  


Why is c++ difficult?

0 Answers  


Where do I find the current c or c++ standard documents?

0 Answers  


Do class method definitions?

0 Answers  


What is a base class?

0 Answers  






What are its advantages and disadvantages of multiple inheritances (virtual inheritance)?

0 Answers  


If horse and bird inherit virtual public from animal, do their constructors initialize the animal constructor? If pegasus inherits from both horse and bird, how does it initialize animal’s constructor?

0 Answers  


how is returning structurs from functions?Show an eg?

1 Answers   GE,


What is unary operator? List out the different operators involved in the unary operator.

0 Answers  


Explain pass by value and pass by reference.

0 Answers  


Explain Memory Allocation in C/C++ ?

0 Answers   Infosys,


What is the rule of three?

0 Answers  


Categories