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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:31:35+00:00 2026-06-17T07:31:35+00:00

I wrote a C program as follows and compiled it using GCC version 4.6.3.

  • 0

I wrote a C program as follows and compiled it using GCC version 4.6.3.

#include <stdio.h>

int main(void)
{
    char array1[7] = "network"; // no space for \0 in array here
    char array2[5] = "network"; // even here, no space for \0 in array

    printf("1. %s\n",array1);
    printf("2. %s\n",array2);
    return 0;
}

On compilation :-

warning: initializer-string for array of chars is too long [enabled by default]

the output of program is :-

1. network
2. netwo

In output for array2 :- netwo+unprintable character.
The non-printable character having hex value 7F.

My question is:-

  • While printing value of array1, why doesn’t it print garbage value after printing “network”
    as in case of printing array2.

This doubt is supported by the fact that there is no NULL terminator in array1 nor in array2, so why garbage value only after array2’s output?

So, does GCC check array bounds?

  • 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-17T07:31:36+00:00Added an answer on June 17, 2026 at 7:31 am

    It doesn’t print garbage after network out of pure bad luck; there happens to be a zero byte around. You’re invoking undefined behaviour, so any result is permitted.

    C compilers do check for overlong initializers, but are explicitly obliged to allow the ‘no terminating null’ version (though they can still warn about it, but usually don’t; GCC 4.7.1 does not).

    For general array access, the compiler does not usually check array bounds, though you can sometimes get information from GCC 4.7.1 under some circumstances (lots of options required, including -O for optimization).

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

Sidebar

Related Questions

I wrote the following program using VS2008: #include <fstream> int main() { std::wofstream fout(myfile);
I wrote a program in C having dangling pointer. #include<stdio.h> int *func(void) { int
Here is my server program #include<stdio.h> #include<stdlib.h> #include<sys/socket.h> #include<sys/un.h> #include<sys/types.h> #include<unistd.h> int main ()
I wrote this program: #include <stdio.h> /*Part B Write a program that: defines an
I wrote a program for downloading an image from web using AsyncTask in service
I wrote a program to click on an application automatically at scheduled time using
I wrote a program in C++/OpenGL (using Dev-C++ compiler) for my calculus 2 class.
I have an example code: #include <quadmath.h> int main() { __float128 foo=123; cosq(foo); return
to understand the concept of relocation, i wrote a simple chk.c program as follows
I wrote this program, where in one part, a thread takes char* buffers and

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.