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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T08:04:16+00:00 2026-06-08T08:04:16+00:00

I have been using arrays for a while now. I have a few questions

  • 0

I have been using arrays for a while now.

I have a few questions that i need to ask.

Now I know i cant use an array without giving a value its element(s).

For example this would give me an error

int fly[5];
cout << fly[4] << endl;

And if i print an element that doesn’t have a set value it would give an error:

int fly[5];
fly[2] = 1;
cout << fly[4] << endl;

Now I found if I give 1 element of the array any number in the array intialization. Then the rest of the elements are set to 0.

So this code prints 0

int fly[5] = {15};
cout << fly[4] << endl;

Why does this happen. Can anyone explain?

  • 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-08T08:04:17+00:00Added an answer on June 8, 2026 at 8:04 am

    It happens because the C++ language standard says it should happen. The standard says it should happen because it’s sensible behaviour and saves a lot of typing in cases where you want a large array initialized.

    Your first couple of examples produce undefined behaviour, in that the value of those array elements can be anything, but they shouldn’t “give an error”. (A sufficiently clever compiler might issue a warning.)

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

Sidebar

Related Questions

I need to create an array of arrays. I have been using array_map(null,$a,$b,$c) to
I've been using J for a few months now, and I find that reading
I have been using Zend Framework for a while now. I am having an
I have been stuck with this problem for a while now, and I just
I've been working on a project using python with OpenGL for a while now.
Is there a pre-implemented linked list out there that would have been implemented using
OK, I've been working on something for a while now, using reflection to accomplish
I have been using Perl for a while but is bothered by one syntax
I have been researching jquery deferred objects for a while now and I'm stumped
I have been working in Storyboards for a while now and they are perfect

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.