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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T21:04:16+00:00 2026-06-12T21:04:16+00:00

I am wondering why the value of register integer a is not overwritten: #include

  • 0

I am wondering why the value of register integer a is not overwritten:

#include <stdio.h>
#include <conio.h>

main()
{
    register int a=10;
    {
        register int a=30;
    }
    printf("%d",a);
    getch();
}

Why isn’t the value of a overwritten? The output is showing 10.

  • 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-12T21:04:17+00:00Added an answer on June 12, 2026 at 9:04 pm

    Having those braces inside your function creates a new nested block. That means that your line:

    register int a=30;
    

    is declaring a new variable that also happens to be called a. If you add another call to printf, you’ll see that happening (I rewrote your program a bit to remove the unnecessary register keywords and cleaned up some things to make it be standard C, too):

    #include <stdio.h>
    
    int main(void)
    {
        int a = 10;
        {
            int a = 30;
            printf("%d\n", a);
        }
        printf("%d\n", a);
        return 0;
      }
    

    The output from this program is:

    30
    10
    

    The inner a (the one set to 30) is said to shadow the other local variable. You can create an arbitrary number of nestings, if you want. For example, this next program:

    #include <stdio.h>
    
    int main(void)
    {
        int a = 10;
        {
            int a = 30;
            {
                int a = 40;
                printf("%d\n", a);
            }
            printf("%d\n", a);
        }
        printf("%d\n", a);
        return 0;
    }
    

    Produces this output:

    40
    30
    10
    

    The redeclarations of a hide all other declarations of a outside the current scope/block. What all of this means is that your original program is semantically equivalent to:

    #include <stdio.h>
    
    int main(void)
    {
        int a = 10;
        printf("%d\n", a);
        return 0;
    }
    

    Since the inner a was set but never used. In fact, turning on some warning flags might let the compiler give some diagnostic messages about what’s going on. I used clang here:

    $ clang -Wunused-variable example.c -o example
    example.c:7:9: warning: unused variable 'a' [-Wunused-variable]
        int a = 30;
            ^
    1 warning generated.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just wondering if the following expressions used for Value are equivalent (the column Contrib
I am wondering if I can change the value of io.sort.mb per job? I
I am wondering what can be the maximum value that a <input type=hidden> can
I am wondering how to get the Json value ?(from below JSOn I would
I was wondering if there is a way to set the tag value of
I am wondering if there is any way to pass in a value when
I'm wondering what is the easiest way to persist a string value, once the
I was wondering if its ok to edit the created_at value of a record
I am wondering if it is possible in R to use a value that
I am wondering if its possible to get $(this).scrollTop() value after an anchor jump.

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.