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

  • SEARCH
  • Home
  • 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 639069
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T20:48:05+00:00 2026-05-13T20:48:05+00:00

The ANSI C grammar from -link- give me the following rules for array declarations:

  • 0

The ANSI C grammar from -link- give me the following rules for array declarations:

 (1) | direct_declarator '[' type_qualifier_list assignment_expression ']'
 (2) | direct_declarator '[' type_qualifier_list ']'
 (3) | direct_declarator '[' assignment_expression ']'
 (4) | direct_declarator '[' STATIC type_qualifier_list assignment_expression ']'
 (5) | direct_declarator '[' type_qualifier_list STATIC assignment_expression ']'
 (6) | direct_declarator '[' type_qualifier_list '*' ']'
 (7) | direct_declarator '[' '*' ']'
 (8) | direct_declarator '[' ']'

Now I have a some questions about these:

  • Can I use (1) – (6) except (3) only in C99?
  • What are (4) and (5) for? The keyword ‘static’ confuses me.
  • Where to use (6)?
  • What’s the difference between the following two function prototypes:

    void foo(int [*]); and

    void foo(int []);

Thank you.

  • 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-05-13T20:48:05+00:00Added an answer on May 13, 2026 at 8:48 pm

    You can’t use type qualifiers or static in size portion of array declaration in C89/90. These features are specific to C99.

    static in array declaration tells the compiler that you promise that the specified number of elements will always be present in the array passed as the actual argument. This might help compilers to generate more efficient code. If you violate your promise in the actual code (i.e. pass a smaller array), the behavior is undefined. For example,

    void foo(int a[static 3]) {
      ...
    }
    
    int main() {
      int a[4], b[2];
      foo(a); /* OK */
      foo(b); /* Undefined behavior */
    }
    

    The * in size portion of array declaration is used in function prototype declarations only. It indicates that the array has variable length (VLA). For example, in the function definition you can use a VLA with a concrete run-time size

    void foo(int n, int a[n]) /* `a` is VLA because `n` is not a constant */
    {
      ...
    }
    

    When you declare the prototype you can do the same

    void foo(int n, int a[n]); /* `a` is VLA because `n` is not a constant */
    

    but if you don’t specify the parameter names (which is OK in the prototype), you can’t use n as array size of course. Yet, if you still have to tell the compiler that the array is going to be a VLA, you can use the * for that purpose

    void foo(int, int a[*]); /* `a` is VLA because size is `*` */
    

    Note, that the example with a 1D array is not a good one. Even if you omit the * and declare the above function as

    void foo(int, int a[]);
    

    then the code will still work fine, because in function parameter declarations array type is implicitly replaced with pointer type anyway. But once you start using multi-dimensional arrays, the proper use of * becomes important. For example, if the function is defined as

    void bar(int n, int m[n][n]) { /* 2D VLA */
      ...
    }
    

    the the prototype might look as follows

    void bar(int n, int m[n][n]); /* 2D VLA */
    

    or as

    void bar(int, int m[*][*]); /* 2d VLA */
    

    In the latter case the first * can be omitted (because of the array-to-pointer replacement), but not the second *.

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

Sidebar

Related Questions

I have a piece of code in ANSI C which uses the time.h library
How to write a ANSI C user-defined function that returns a specific line from
Given the following ANSI C code, I wonder about the results: main() { int
In ANSI C++, how can I assign the cout stream to a variable name?
Using only ANSI C, what is the best way to, with fair certainty, determine
Quite often in ANSI C code I can see parenthesis sorrounding a single return
Using only ANSI C, is there any way to measure time with milliseconds precision
T-SQL: 1(ANSI): convert(varchar(10),@DueDate, 102) < convert(varchar(10),getdate(), 102) 2(USA): convert(varchar(10),@DueDate, 101) < convert(varchar(10),getdate(), 101) Notice
My boss asks me to write only ANSI SQL to make it database independent.
Why are SQL distributions so non-standard despite an ANSI standard existing for SQL? Are

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.