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 453127
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T22:08:28+00:00 2026-05-12T22:08:28+00:00

I am learning C and I am playing around with pointers and arrays. I

  • 0

I am learning C and I am playing around with pointers and arrays. I am trying to create an array of pointers with the code below:

const int NUM_P = 50; // Line 10
char *pS[NUM_P] = { NULL }; // Line 11

I am getting the following warnings and errors when I compile:

→ gcc array.c -o array
array.c: In function ‘main’:
array.c:11: error: variable-sized object may not be initialized
array.c:11: warning: excess elements in array initializer
array.c:11: warning: (near initialization for ‘pS’)

I cannot figure this error out, I have looked online and been unable to find a explanation and solution of the problem.

Can anyone help out?

Cheers

Eef

  • 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-12T22:08:28+00:00Added an answer on May 12, 2026 at 10:08 pm

    Your main problem is the initialization line (= {NULL};) because apparently you can’t initialize an array that way when the array’s size is a variable. If you use #define NUM_P 50 to force the array size to be a true compile-time constant, then the array would not have a variable size, and your initialization method would compile fine.

    As a side note, the difference between #define NUM_P 50 and const int NUM_P = 50 is that C89 does not allow the use of variables as array dimensions, but C99 does; however, C99 is not fully supported by all compilers yet. The fact that gcc accepts your character array with a size of NUM_P is not C89-compliant.

    Technically, you could use a flag on the command line to tell gcc that you want to compile in C99:

    gcc -std=c99 FILE.c
    

    By the way, when learning C, start at the top of the errors listed and work down from there. In this case, the warnings are not of any concern until you’ve taken care of the error at the top: “variable-sized object may not be initialized”.

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

Sidebar

Related Questions

I have been playing around with wf4 for a while. I found various articles,
I'm new to Python, and I've been playing around with it for simple tasks.
Hey I am learning Grails. I've been playing with it for a while but
Hopefully someone can help, I've been playing with ASP.NET MVC 2 for a learning
I'm starting learning android development, so my knowledge is really limited at the moment.
I'm assuming my lack of knowledge (I just started learning Flex yesterday, hah!) is
Learning C++, came upon function templates. The chapter mentioned template specialization. template <> void
I have so far been a dedicated Wordpress user, but have been researching other
I've pretty much finished work on a white noise feature for one of my
I am new to jQuery and I am having trouble with the syntax, selectors

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.