Build a complete dynamic array instance using C language, dynamic array

Source: Internet
Author: User

[Go to] C language to build a complete dynamic array instance, dynamic array

[Switch] C language to build a complete dynamic array instance

Address: http://www.jb51.net/article/52153.htm

 

This article uses a complete example code to briefly describe how to build a dynamic array in C language for your reference. The complete example is as follows:

?
123456789101112131415161718 #include <stdio.h>#include <malloc.h>int main(void) {    int len;    int * arr;    printf("Enter the length of the array :");    scanf("%d", &len);    arr = (int *)malloc(sizeof(int)*len);    printf("Enter the value of the array :");    for ( int i = 0; i < len; i ++) {        scanf("%d", &arr[i]);    }    for (int j = 0; j < len; j ++) {        printf("%d:%d ", j , arr[j]);    }    free(arr);    return 0;}

The running result is as follows:

?
12345 E:\clearning\cpointer>gcc dynamicarray.c -o dm --std=c99E:\clearning\cpointer>dmEnter the length of the array: 5Enter the value of the array: 1 2 3 4 50:1 1:2 2:3 3:4 4:5

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.