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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T05:42:19+00:00 2026-05-13T05:42:19+00:00

is this form of intializing an array to all 0s char myarray[ARRAY_SIZE] = {0}

  • 0

is this form of intializing an array to all 0s

char myarray[ARRAY_SIZE] = {0} supported by all compilers? ,

if so, is there similar syntax to other types? for example

bool myBoolArray[ARRAY_SIZE] = {false} 
  • 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-13T05:42:19+00:00Added an answer on May 13, 2026 at 5:42 am

    Yes, this form of initialization is supported by all C++ compilers. It is a part of C++ language. In fact, it is an idiom that came to C++ from C language. In C language = { 0 } is an idiomatic universal zero-initializer. This is also almost the case in C++.

    Since this initalizer is universal, for bool array you don’t really need a different “syntax”. 0 works as an initializer for bool type as well, so

    bool myBoolArray[ARRAY_SIZE] = { 0 };
    

    is guaranteed to initialize the entire array with false. As well as

    char* myPtrArray[ARRAY_SIZE] = { 0 };
    

    in guaranteed to initialize the whole array with null-pointers of type char *.

    If you believe it improves readability, you can certainly use

    bool myBoolArray[ARRAY_SIZE] = { false };
    char* myPtrArray[ARRAY_SIZE] = { nullptr };
    

    but the point is that = { 0 } variant gives you exactly the same result.

    However, in C++ = { 0 } might not work for all types, like enum types, for example, which cannot be initialized with integral 0. But C++ supports the shorter form

    T myArray[ARRAY_SIZE] = {};
    

    i.e. just an empty pair of {}. This will default-initialize an array of any type (assuming the elements allow default initialization), which means that for basic (scalar) types the entire array will be properly zero-initialized.

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

Sidebar

Related Questions

I have this form with a date input. echo $this->Form->create('Nodata'); echo $this->Form->input('date1', array('type' =>
what will be correct form of this code in c? char *x = malloc(100);
this the condition: there is a form in html and php haivng around 120
This form has a NotifyIcon object. When the user clicks on the Close button,
I have this form, in which i need to populate a combo box with
I have this form: <%= form_tag posts_path, :method => :get, :class => search_nav do
i have this form to serialize once i click the submit button, <form class=cashier_forms
I want to make this form: echo '<form method=post action=ratinghandler.php style=width: 250px> <input type=hidden
I have inserted this form with multiple checkbox items which collects some values, What
I have this form: <tbody> <tr> <th>ID</th> <th>Name</th> <th>Birthdate</th> <th><input type=text autofocus=autofocus name=textinput1/></th> <th><input

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.