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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T07:13:03+00:00 2026-06-14T07:13:03+00:00

I’ve been using the code below to read two different matrices from text files.

  • 0

I’ve been using the code below to read two different matrices from text files.
The code repeatedly re-declares (at least, I think it re-declares) the local variables stringvalues and iss. I just now realized that the variables are re-declared–I certainly didn’t intend to re-declare them.

Question: what is the effect of repeatedly re-declaring these variables?

FYI: I’m compiling with GCC 4.4.3.

fstream PW3_in("./input/PW.txt", ios::in);
for(int i=0; i<900; i++)
{
    PW3_in.getline(line, 450);

    string stringvalues;
    stringvalues = line;
    istringstream iss (stringvalues,istringstream::in);

    iss >> word1 >> word2 >> word3 >> word4 >> word5 >> word6 >> word7 >> word8 >> word9;

    num1 = strtod(word1, NULL);
    num2 = strtod(word2, NULL);
    num3 = strtod(word3, NULL);
    num4 = strtod(word4, NULL);
    num5 = strtod(word5, NULL);
    num6 = strtod(word6, NULL);
    num7 = strtod(word7, NULL);
    num8 = strtod(word8, NULL);
    num9 = strtod(word9, NULL);

    PW3[0+i*9]=num1;
    PW3[1+i*9]=num2;
    PW3[2+i*9]=num3;
    PW3[3+i*9]=num4;
    PW3[4+i*9]=num5;
    PW3[5+i*9]=num6;
    PW3[6+i*9]=num7;
    PW3[7+i*9]=num8;
    PW3[8+i*9]=num9;

}
PW3_in.close();


fstream PP3_in("./input/PP.txt", ios::in);
for(int i=0; i<900; i++)
{
    PP3_in.getline(line, 450);

    string stringvalues;
    stringvalues = line;
    istringstream iss (stringvalues,istringstream::in);

    iss >> word1 >> word2 >> word3 >> word4 >> word5 >> word6 >> word7 >> word8 >> word9;

    num1 = strtod(word1, NULL);
    num2 = strtod(word2, NULL);
    num3 = strtod(word3, NULL);
    num4 = strtod(word4, NULL);
    num5 = strtod(word5, NULL);
    num6 = strtod(word6, NULL);
    num7 = strtod(word7, NULL);
    num8 = strtod(word8, NULL);
    num9 = strtod(word9, NULL);

    PP3[0+i*9]=num1;
    PP3[1+i*9]=num2;
    PP3[2+i*9]=num3;
    PP3[3+i*9]=num4;
    PP3[4+i*9]=num5;
    PP3[5+i*9]=num6;
    PP3[6+i*9]=num7;
    PP3[7+i*9]=num8;
    PP3[8+i*9]=num9;

}
PP3_in.close();
  • 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-14T07:13:04+00:00Added an answer on June 14, 2026 at 7:13 am

    Yes, it re-declares them. But each declaration is actually a different variable. Much like if you called something x in two different function declarations.

    That variable is showing up declared at the beginning of a block. A variable goes ‘out-of-scope’ (i.e. it’s destroyed and doesn’t exist anymore) after the block in which it was declared ends.

    In fact, that variable is destroyed and re-created once for every single iteration of the for loop. Each time it has the same name, but is conceptually a completely different variable (even if it occupies the same spot in memory).

    Also, if you tried to use the variable stringvalues between the two for loops, the compiler would give you an error because the variable doesn’t exist there.

    So, even though those two variable declarations declare variables with the same name, those variables are actually different variables. You could just rename the one in the second block to have a 1 on the end of the name and the effect would be exactly the same.

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

Sidebar

Related Questions

I have a bunch of posts stored in text files formatted in yaml/textile (from
For some reason, after submitting a string like this Jack’s Spindle from a text
I've tracked down a weird MySQL problem to the two different ways I was
I have a text area in my form which accepts all possible characters from
Does anyone know how can I replace this 2 symbol below from the string
I have thousands of HTML files to process using Groovy/Java and I need to
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has

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.