The "C language" initializes, empties, reverse, and displays an array.

Source: Internet
Author: User

(i) initializing an array

Initializes an array of length 10 to 10,9,8,7,6,54,3,2,1

#include <stdio.h>voidInitint*PA,intN) { for(PA; pa<pa+n; pa++,n--)    {*PA = n; }}intMain () {inta[Ten];inti =0;intm =sizeof(a)/sizeof(a[0]); Init (a,m); for(i=0; i<m; i++) {printf("%d", A[i]); }printf("\ n");return 0;}
(b) empty the array.

The contents of an array are completely cleared to 0.

#include <stdio.h>voidEmptyint*PA,intN) { for(PA; pa<pa+n; pa++,n--) {*pa =0; }}intMain () {inta[Ten] ={1,2,3,4,5,6,7,8,9,Ten};inti =0;intm =sizeof(a)/sizeof(a[0]); Empty (a,m); for(i=0; i<m; i++) {printf("%d", A[i]); }printf("\ n");return 0;}
(iii) array in reverse order

Arranges an array in reverse order and outputs.

#include <stdio.h>voidSort(int *pa,intN) {int *r= pa+n-1; for(; pa<r; pa++,r--) {intTMP =*pa;*pa=*r;*r= tmp; }}intMain () {inta[Ten] = {1,2,3,4,5,6,7,8,9,Ten};inti =0;int m= sizeof (a)/sizeof (a[0]);SortAm); for(i=0; i<m; i++) {printf("%d ", A[i]); }printf("\ n");return 0;}
(iv) displays an array.

Displays the contents of the array.

#include <stdio.h>void Show (int *pa,intN) {int *r= Pa+n; for(; pa<r; pa++) {printf("%d ",*pa); }}intMain () {inta[Ten] = {1,2,3,4,5,6,7,8,9,Ten};int m= sizeof (a)/sizeof (a[0]); Show (A,m);printf("\ n");return 0;}

The "C language" initializes, empties, reverse, and displays an array.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.