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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T22:34:16+00:00 2026-05-12T22:34:16+00:00

I read this question and its answer in a book. But I didn’t understand

  • 0

I read this question and its answer in a book. But I didn’t understand the book’s justification.

Will the following code compile?

int main()
{
   char str[5] = "fast enough";
   return 0;
}

And the answer was:

Yes.The compiler never detects the
error if bounds of an array are
exceeded.

I couldn’t get it.

Can anybody please explain this?

  • 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-12T22:34:16+00:00Added an answer on May 12, 2026 at 10:34 pm

    In the C++ standard, 8.5.2/2 Character arrays says:

    There shall not be more initializers than there are array elements.

    In the C99 standard, 6.7.8/2 Initialization says:

    No initializer shall attempt to provide a value for an object not contained within the entity
    being initialized

    C90 6.5.7 Initializers says similar.

    However, note that for C (both C90 and C99) the ‘\0’ terminating character will be put in the array if there is room. It’s not an error if the terminator will not fit (C99 6.7.8/14: “Successive characters of the character string literal (including the terminating null character if there is room or if the array is of unknown size) initialize the elements of the array”).

    On the other hand, the C++ standard has an example that indicates an error should be diagnosed if there’s not room for the terminating character.

    in either case, this should be diagnosed as an error in all compilers:

    char str[5] = "fast enough";
    

    Maybe pre-ANSI compilers weren’t so strict, but any reasonably modern compiler should diagnose this.

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

Sidebar

Related Questions

Prerequisities: To understand this question, please, read the following question and its answer at
I've read so many articles, but none seem to answer this question. Or maybe
I have read this question and found its answer to be useful to check
I've already read this but it doesn't answer to my question. Here's my scenario:
I have read this question but it's not quite what I was looking for.
I've read this question, but I want to know how can I delete the
I've read this question mentioning Code Bubbles and I've watched their video presentation. The
I just read this question and the accepted answer: What is JavaScript garbage collection?
I'm showing the code to this problem for example purposes, but really my question
(I hope this question is on-topic -- I tried searching for an answer but

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.