Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

C Language Examples - Copying an Array

C Language Examples - Copying an Array

C Language Examples C Language Examples

Copy one array to another array:

Example

#include

<

stdio.h

int

main

(

)

{

int

original

[

10

]

=

{

1

,

2

,

3

,

4

,

5

,

6

,

7

,

8

,

9

,

0

}

;

int

copied

[

10

]

;

int

loop

;

for

(

loop

=

0

;

loop

<

10

;

loop

++

)

{

copied

[

loop

]

=

original

[

loop

]

;

}

printf

(

"

Element array -> copied array

\

n

"

)

;

for

(

loop

=

0

;

loop

<

10

;

loop

++

)

{

printf

(

"

%2d %2d

\

n

"

,

original

[

loop

]

,

copied

[

loop

]

)

;

}

return

0

;

}

The output is:



元素数组 -> 拷贝后的数组 

    1         1

    2         2

    3         3

    4         4

    5         5

    6         6

    7         7

    8         8

    9         9

    0         0

C Language Examples C Language Examples