Can you define the size of an array at runtime in C

后端 未结 10 1201
走了就别回头了
走了就别回头了 2021-01-02 18:35

New to C, thanks a lot for help.

Is it possible to define an array in C without either specifying its size or initializing it.

For example, can I prompt a u

10条回答
  •  走了就别回头了
    2021-01-02 18:56

    Yes, absolutely. C99 introduced the VLA or Variable Length Array. Some simple code would be like such:

    #include 
    
    int main (void) {
    
        int arraysize;
        printf("How bid do you want your array to be?\n");
        scanf("%d",&arraysize);
        int ar[arraysize];  
        return 0;
    }
    

提交回复
热议问题