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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:03:44+00:00 2026-06-13T23:03:44+00:00

I have a question about the initialization of static variables in C. I know

  • 0

I have a question about the initialization of static variables in C. I know if we declare a global static variable that by default the value is 0. For example:

static int a; //although we do not initialize it, the value of a is 0

but what about the following data structure:

typedef struct
{
    int a;
    int b;
    int c;
} Hello;

static Hello hello[3];

are all of the members in each struct of hello[0], hello[1], hello[2] initialized as 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-06-13T23:03:45+00:00Added an answer on June 13, 2026 at 11:03 pm

    Yes, all members are initialized for objects with static storage. See 6.7.8/10 in the C99 Standard (PDF document)

    If an object that has automatic storage duration is not initialized explicitly, its value is indeterminate. If an object that has static storage duration is not initialized explicitly, then:
    — if it has pointer type, it is initialized to a null pointer;
    — if it has arithmetic type, it is initialized to (positive or unsigned) zero;
    — if it is an aggregate, every member is initialized (recursively) according to these rules;
    — if it is a union, the first named member is initialized (recursively) according to these
    rules.

    To initialize everything in an object, whether it’s static or not, to 0, I like to use the universal zero initializer

    sometype identifier0 = {0};
    someothertype identifier1[SOMESIZE] = {0};
    anytype identifier2[SIZE1][SIZE2][SIZE3] = {0};
    

    There is no partial initialization in C. An object either is fully initialized (to 0 of the right kind in the absence of a different value) or not initialized at all.
    If you want partial initialization, you can’t initialize to begin with.

    int a[2]; // uninitialized
    int b[2] = {42}; // b[0] == 42; b[1] == 0;
    a[0] = -1; // reading a[1] invokes UB
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a question about the default initialization in C++. I was told the
I have a question about how to catch the exception in the initialization list.
I have a question about how is the correct way of manipulate the initialization
I have a question about inner-workings of Python sub-interpreter initialization (from Python/C API) and
I have a question about the moment of StreamSource initialization for Xalan transformation. This
I've a question about initialization of inherited members in constructor of derived class. Example
Right now I'm working on my project and I have a question about initialization
I have a crazy question about Java switches. int key = 2; switch (key)
I have question about parsing in Html helper : I have sth like: @foreach
I have question about clean thory in Python. When: @decorator_func def func(bla, alba): pass

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.