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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T06:43:11+00:00 2026-05-17T06:43:11+00:00

I used to initialize my structures in this way: struct A a = {0};

  • 0

I used to initialize my structures in this way:

struct A a = {0};

This seems to work for me, however I was argued about ANSI C, C89, C99 standard.
Simply I couldn’t find that in any documentation.
Could you help me with that?
Here’s an example that this works for ‘cl’ (VS express 2008).

#include <stdio.h>
struct DATA
{
    int a;
    int b;
    char tab[3];
};


int main(void)
{
    struct DATA A;
    struct DATA B = {0};

    printf("A.a: %d, A.b: %d, A.tab: %s\n", A.a, A.b, A.tab);
    printf("B.a: %d, B.b: %d, B.tab: %s", B.a, B.b, B.tab);
};
>>>>>OUTPUT:
D:\N\workspace>test.exe

A.a: 4203600, A.b: 451445257, A.tab: ■   
B.a: 0, B.b: 0, B.tab:

This one shows that it initialize first with 1, rest with 0’s.

#include <stdio.h>
#include <stdlib.h>

typedef struct {
    int a;
    int b;
} ASDF;

ASDF A = {1};

int main()
{
    printf("a:%d,b:%d\n",A.a,A.b);
    return 0;
}
Output:
a:1,b:0
  • 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-17T06:43:11+00:00Added an answer on May 17, 2026 at 6:43 am

    You are right, this always work. The relevant section in the C99 draft N1256 is 6.7.8 (Initialization):

    21. If there are fewer initializers in a brace-enclosed list than there are elements or members of an aggregate, or fewer characters in a string literal used to initialize an array of known size than there are elements in the array, the remainder of the aggregate shall be
    initialized implicitly the same as objects that have static storage duration.

    Objects of static storage duration are initialised to zero (paragraph 10 of the same section).

    The ANSI standard is shorter, but similar in 3.5.7:

    If there are fewer initializers in a list than there are members of
    an aggregate, the remainder of the aggregate shall be initialized
    implicitly the same as objects that have static storage duration.

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

Sidebar

Related Questions

In our code we used to have something like this: *(controller->bigstruct) = ( struct
When {0} is used to initialize an object, what does it mean? I can't
Never used a cache like this before. The problem is that I want to
I used to work in a place where a common practice was to use
When used like this: import static com.showboy.Myclass; public class Anotherclass{} what's the difference between
We used to use SourceSafe, and one thing I liked about it was that
A wide range of structures is used in Win32 programming. Many times only some
I always used to consider structures as some sort of lesser privileged things, or
I have a really strange problem with the standard logging module used in django
I notice in several API's, that you may create a struct which is used

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.