Shadow variable value

This is a discussion on Shadow variable value within the C Programming forums, part of the General Programming Boards category; Hi , Is there any way to get the value of a global variable to a method in C which ...

  1. #1
    Registered User
    Join Date
    Mar 2005
    Posts
    1

    Shadow variable value

    Hi ,
    Is there any way to get the value of a global variable to a method in C which has the same variable declared in it ? For eg:

    Code:
    #include <stdio.h>
    # include <conio.h>
    
    int i=4;
    
    int main()
    {
     int i=5;
     printf(" i is %d ",i );  
     getch();  
    }
    Is there any way to get the value of the global variable i=4 in the method main() which is possible in C++ (using scope resolution operator)

  2. #2
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    no, it is not
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  3. #3
    Registered User
    Join Date
    Jun 2005
    Posts
    6,301
    The workaround, however, is simple: change the name of the local variables within the function. Rationale: if you have a function that needs to do this, you have access to the implementation of that function, and can therefore change the names of local variables to your hearts content.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Question about printing a variable???
    By Hoser83 in forum C++ Programming
    Replies: 2
    Last Post: 03-31-2006, 12:57 PM
  2. How accurate is the following...
    By emeyer in forum C Programming
    Replies: 22
    Last Post: 12-07-2005, 11:07 AM
  3. Replies: 2
    Last Post: 04-12-2004, 01:37 AM
  4. write Variable and open Variable and get Information
    By cyberbjorn in forum C++ Programming
    Replies: 2
    Last Post: 04-09-2004, 01:30 AM
  5. Variable question I can't find answer to
    By joelmon in forum C++ Programming
    Replies: 3
    Last Post: 02-12-2002, 03:11 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21