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

What are the advantages of inheritance in c++?

0 Answers  


What is a flag in c++?

0 Answers  


What are all predefined data types in c++?

0 Answers  


Explain the difference between abstract class and interface in c++?

0 Answers  


Generally variables are stored in heap memory. When he variables are created in stack?

4 Answers   Persistent,






Why do we use the using declaration?

0 Answers  


How can you quickly find the number of elements stored in a static array? Why is it difficult to store linked list in an array?

0 Answers  


How do you know that your class needs a virtual destructor?

5 Answers   Lucent,


What is the use of pointer in c++ with example?

0 Answers  


Is atoi safe?

0 Answers  


Describe new operator and delete operator?

0 Answers  


What is the size of a vector?

0 Answers  


Categories