Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
C Array copy example 
 

The example below contains two arrays: array1 and array2 with sizes 5 respectively.

 

C Array copy example

                         

In this section, you will learn how to copy an array in C.

The example below contains two arrays: array1 and array2 with sizes 5 respectively. Here the size of an array states its capacity to hold maximum number of values. 

Now in the example each element of array1 is assigned a value. Then, in order to copy the elements of array1 into array2, we have used for loop with which the values located at the indexes of array1 will be as it is get copied and pasted at the same indexes of array2.

Here is the code:

ARRAYCOP.C

#include <stdio.h>
#include <conio.h>
int main() {
  clrscr();
  int array1[5];
  int array2[5];
  int i, j;
  array1[0]=10;
  array1[1]=20;
  array1[2]=30;
  array1[3]=40;
  array1[4]=50;
  for (i=0; i<5; i++)
    array2[i]=array1[i];
  for (j=0; j<5; j++)
    printf("The value of %d=%d\n", j, array2[j]);
  getch();
  return 0;
}

The array is copied consisting of same elements:

ARRAYCOP.EXE

Download Source Code:

                         

» View all related tutorials
Related Tags: c array integer size type int ai max example maximum contains exam e ax pe im in m nt xa

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.