Thread: Shadow variable value

  1. #1
    Registered User
    Join Date
    Mar 2005

    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:

    #include <stdio.h>
    # include <conio.h>
    int i=4;
    int main()
     int i=5;
     printf(" i is %d ",i );  
    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
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Rishon LeZion, Israel
    no, it is not
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    David J. Wheeler

  3. #3
    Registered User
    Join Date
    Jun 2005
    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, 01:57 PM
  2. How accurate is the following...
    By emeyer in forum C Programming
    Replies: 22
    Last Post: 12-07-2005, 12:07 PM
  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, 04:11 AM