Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7860659
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T22:22:37+00:00 2026-06-02T22:22:37+00:00

How is it possible to declare a variable-length array as a global variable ?

  • 0

How is it possible to declare a variable-length array as a global variable ?

when variable length array is declared in a function before the length is scanned, it compiles but does not run. it gives segmentation fault. when the same declaration statement is shifted below the scanning statement, it runs fine.

in case we want a variable length array globally available to all functions, how can we do that? problem here is the that the length of the array can only be scanned through some function only.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T22:22:42+00:00Added an answer on June 2, 2026 at 10:22 pm

    You can’t do that.
    Here’s what the draft of the standard says:

    6.7.6.2 Array declarators

    2 If an identifier is declared as having a variably modified type, it
    shall be an ordinary identifier (as defined in 6.2.3), have no
    linkage, and have either block scope or function prototype scope. If
    an identifier is declared to be an object with static or thread
    storage duration, it shall not have a variable length array type.

    Also,

    10 EXAMPLE 4 All declarations of variably modified (VM) types have to be at either block scope or
    function prototype scope. Array objects declared with the _Thread_local, static, or extern
    storage-class specifier cannot have a variable length array (VLA) type. However, an object declared with
    the static storage-class specifier can have a VM type (that is, a pointer to a VLA type). Finally, all
    identifiers declared with a VM type have to be ordinary identifiers and cannot, therefore, be members of
    structures or unions.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

is it possible to declare a variable length array with global scope in objective-c?
Possible Duplicate: Declaring a global variable inside a function Is it possible to declare
Why is not possible to initialize a property to a function when you declare
Correct me if I am wrong, but isn't it possible to declare a variable
In Java, is it possible to declare a field/variable whose type is multiple interfaces?
Is it possible to declare more than one variable using a with statement in
I would like to know if it's possible in java to declare a variable
Possible Duplicate: Why can't I create an array with size determined by a global
Is it possible to declare global variables in MATLAB inside a loop: cellvar =
Is it possible to declare variable in @protocol? Just to force programmers to add

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.