This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

How initialize an array with non-constant variables in c?

hi to all

sorry but i did not have any option. i know this is not the proper forum for this question but i struck very badly.please suggest any way.

not google i done that already

any alternate option also welcome

How initialize an array with non-constant variables in c?

Parents
  • "not google i done that already"

    What about your 'C' textbook?

    ISO/IEC 9899:1990 states:

    "Array and structure types are collectively called aggregate types"

    And:

    "All the expressions in an ... initialiser list for an object that has aggregate or union type shall be constant expressions"

    So your array initialisers have to be constants - they cannot be variables!

    c-faq.com/.../constasconst.html

Reply
  • "not google i done that already"

    What about your 'C' textbook?

    ISO/IEC 9899:1990 states:

    "Array and structure types are collectively called aggregate types"

    And:

    "All the expressions in an ... initialiser list for an object that has aggregate or union type shall be constant expressions"

    So your array initialisers have to be constants - they cannot be variables!

    c-faq.com/.../constasconst.html

Children
  • ISO/IEC 9899:1990 also states:

    "The initialiser for a structure or union object that has automatic storage duration either shall be an initiliser list ... or shall be a single expression that has compatible structure or union type."

    So, if you could wrap your array in a structure, that might help...