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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T22:03:49+00:00 2026-06-09T22:03:49+00:00

Suppose we have something along these lines int f(int n); …. do{ int a

  • 0

Suppose we have something along these lines

int f(int n);

….

do{
    int a = b;
    int b = f(a);
}

Is there any risk to saying

do{
    int b = f(b);
}

instead, assuming a is not used elsewhere? Would it be stylistically preferable to do the former?

  • 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-09T22:03:51+00:00Added an answer on June 9, 2026 at 10:03 pm

    It is important to understand that you’re not “altering” any variables here, just changing the meaning of a name.

    The important concept is called the point of declaration.

    Let’s look at your example:

    int b = 42;
    { 
       int a = b; 
       int b = 23 * a;
       printf("%d\n", b);
    }
    printf("%d\n", b); 
    

    or

    int b = 42;
    { 
       int b = 23 * b;
       printf("%d\n", b);
    }
    printf("%d\n", b); 
    

    The name b references two objects, depending on where you are in the code, let’s call them b1 and b2. This is unsurprising in case 1:

    int b1 = 42;
    { 
       int a = b1; 
       int b2 = 23 * a;
       printf("%d\n", b2);
    } 
    printf("%d\n", b1); 
    

    Since in C the point of declaration is before the initializer, the second example resolves differently:

    int b1 = 42;
    { 
       int b2 = 23 * b2; 
       printf("%d\n", b2);
    } 
    printf("%d\n", b1); 
    

    Note that here there’s no link between b1 and b2, you’re initializing b2 with its own (undefined) value. A diligent compiler will warn you about this, like

    x.c:7:13: warning: 'b' is used uninitialized in this function [-Wuninitialized]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have something like this: class A { public B mem; public int
Suppose I have something like the following in test.cxx (and that I do the
Suppose you have something like this: class intlist: def __init__(self,l = []): self.l =
Suppose I have something like this page: <noscript>You need JS for this page</noscript> <script>
Suppose I have something like this: if ($command === 'txt') { header('Content-type: text/plain;charset=utf-8'); echo
Suppose I have a BaseForm which depends on an ILogger or IResourceManager or something
suppose I have a function: function test(){} test.prototype.method01=function(){ //do something } test.prototype.method02=function(){ //how can
Suppose I have a table of users. Something like: ID integer, USER text, POSITION
Here's something I've been thinking about: suppose you have a number, x, that can
I feel like there must be something really simple that I'm not seeing here.

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.