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 files in c++?

0 Answers  


List different attributes in C++?

0 Answers   Ericsson,


Do you know the problem with overriding functions?

0 Answers  


How would you obtain segment and offset addresses from a far address of a memory location?

0 Answers  


Define precondition and post-condition to a member function?

1 Answers  






What is class invariant?

1 Answers  


What are mutator methods in c++?

0 Answers  


Is c++ still being used?

0 Answers  


What is binary search in c++?

0 Answers  


Name four predefined macros.

0 Answers  


What does getch() do according to the ANSI C++ standard a) Reads in a character b) Checks the keyboard buffer c) Nothing in particular (Its not defined there)

0 Answers  


If we want that any wildcard characters in the command line arguments should be appropriately expanded, are we required to make any special provision? If yes, which?

0 Answers  


Categories