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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T07:26:48+00:00 2026-05-16T07:26:48+00:00

char *names[] = { [3] = foo, [1] = bar, [0] = man}; int

  • 0
char *names[] = {
        [3] = "foo", 
        [1] = "bar", 
        [0] = "man"};

int i;
for (i=0; i<sizeof(names)/sizeof(char); i++)
{
    puts(names[i]);
}

What are the function of the brackets in the above declaration? Also, why does the resulting loop iterate 3 times instead of 4 and produce this output:

man

bar

  • 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-16T07:26:49+00:00Added an answer on May 16, 2026 at 7:26 am

    The numbers in brackets are the indices of the initializers. This is a C99 feature.

    Given that your example code does use this blemish, the reason you receive the output you do is that “foo” is stored in names[3], while NULL is stored in names[2]. Your program crashes when it attempts to puts(names[2]) which is the same as puts(NULL).

    Your loop would otherwise iterate to 16 or 32 iterations — you are dividing by sizeof(char) for the array element size, and you mean to use sizeof(char *).

    Better to use this macro:

    #define DIMENSION_OF (a) (sizeof(a)/sizeof(a[0]))
    

    I suggest never using any C99-specific features, such as these “designated initializers.”

    There is a reason that most of the answers you received on this question were confused as to why your loop only output two strings rather than four. That reason is that C99 is not widely recognized by other programmers.

    There are several reasons that most programmers aren’t familiar with C99’s more distinctive features. A frequently cited reason is that C99 is more incompatible with C++ than ANSI C, and makes the possibility of future conversion to C++ more difficult. My personal complaint with C99 also makes extensions to ANSI C which are superfluous. An example of a superfluous addition is the example from C99 that you have provided. Don’t use “designated inits.” Do refer to the American National Standards Institute C Standard. Do not refer to the International Standards Organization C99 document.

    Most of the features which are “nice to have” form C99 were already available as extensions in all major compilers. Declaring a variable in the for-init-statement is an example of a non-ANSI-C-standard feature which is widely supported. The complex built-in type is an example of a non-ANSI-C-standard feature that is not widely supported.

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

Sidebar

Ask A Question

Stats

  • Questions 491k
  • Answers 491k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer no. It'll work just fine. May 16, 2026 at 10:17 am
  • Editorial Team
    Editorial Team added an answer you want: Update: fixed a bug <%: Html.ListBox("lala", new SelectList(movies,… May 16, 2026 at 10:17 am
  • Editorial Team
    Editorial Team added an answer You need the sites on two different IP addresses, as… May 16, 2026 at 10:17 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

Code #include <OOLua/oolua.h> class foo { public: int bar(); }; OOLUA_CLASS_NO_BASES(foo)//class has no bases
Say I have a macro, FOO(name), and some template class Bar<> that takes one
Suppose we have some named enums: enum MyEnum { FOO, BAR = 0x50 };
gcc 4.4.4 c89 #define SIZE 5 char *names[SIZE] = {peter, lisa, simon, sarah, julie};
I have a function that returns an array of different lengths based on a
In C, unlike C++, all parameters to a function definition must be named. Instead
Hi I'm working with C and I have a question about assigning pointers. struct
I have a file in a known format and I want to convert it
Our C++ application reads configuration data from XML files that look something like this:
In the type of embedded programming I'm getting into, determinism and transparency of the

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.