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

Can union be self referenced?

0 Answers  


What is expression parser in c++

0 Answers   Mphasis,


Can we delete this pointer in c++?

0 Answers  


Write a code/algo to find the frequency of each element in an array?

0 Answers   Axtria,


Is c++ a float?

0 Answers  






What is an operator in c++?

0 Answers  


Why namespace is used in c++?

0 Answers  


Write a program which employs Recursion

0 Answers  


How do I tokenize a string in c++?

0 Answers  


Can you help me with this one? Make a program that when a user inputed a Product Name, it will display its price, and when the user inputed the quantity of the inputed product, it will show its total price. The output must be like this: Product Name: Price: Quantity: Total Price: ..this is the list of products to be inputed: Cellphone - 1500 Washing Machine - 5200 Television - 6000 Refrigirator - 8000 Oven - 2000 Computer - 11000 thanks..:D

1 Answers  


Explain the properties and principles of oop.

0 Answers  


What is a virtual destructor?

2 Answers  


Categories