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

  • Home
  • SEARCH
  • 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 8155155
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T16:35:16+00:00 2026-06-06T16:35:16+00:00

Why the following program is not printing garbage values . As i know ,

  • 0

Why the following program is not printing garbage values . As i know , array allocated memory on stack(ie at compile time) and stack memory contain some garbage value . But its not printing garbage values . It is printing 1’s . It will print garbage value only when if in function g() , size of array b > size of array a . When size of array in g() > size of array a , then it is printing 12 1’s(in this case) and rest as garbage values .

    void f()
    {
        int a[12],i=0;
        for(i=0;i<12;i++)
          a[i]=1;
    }
    void g()
    {
        int b[12],i=0;
        for(i=0;i<12;i++)
          printf("%d\n",b[i]);
    }
    int main()
    {
         f();
         g();
          return 0;
    }

Does the memory allocated to array b is same as the memory allocated to array a previously ?

  • 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-06T16:35:17+00:00Added an answer on June 6, 2026 at 4:35 pm

    It IS garbage, left by function f() – and this effect is not defined. The effect is a by-product of how the compiler allocates and deallocates local variables on the stack.

    The compiler can produce code to totally overwrites the stack with random data when the function returns, or it can just produce code to modify the stack pointer, which is what it does in this case.

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

Sidebar

Related Questions

I am not able to compile the following program because of cyclic dependency between
When answering another question, I realized that the following program does not quite do
Why is the output of the following program just int3 and not int3&4 ?
The following program I'm creating will allow the user will input values to create
let us have a situation in which the following program prints some 10 lines
I am printing some data from a C++ program to be processed/visualized by ParaView,
Can anyone spot why the following script is not printing the passed arguments? import
The following program expects user input in the mixed fraction format 'whole_numbernumerator/denominator' and assigns
The following program, compiled with g++ 4.6, yields the error request for member ‘y’
The following program: import multiprocessing,operator f = operator.itemgetter(0) # def f(*a): return operator.itemgetter(0)(*a) if

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.