Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. Article Writing
  4. C++ Doubt

C++ Doubt

Scheduled Pinned Locked Moved Article Writing
c++tutorial
3 Posts 3 Posters 18 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Santosh Rao
    wrote on last edited by
    #1

    #include int i = 7; //The above i can be accessed using the global namespace //:: Operator void main() { int i = 10; { int i = 15; { int i = 17; printf("%d\n",i); //How to Access The Remaining i's here in c and c++ } } } //The above variables have to be defined at the above point

    C A 2 Replies Last reply
    0
    • S Santosh Rao

      #include int i = 7; //The above i can be accessed using the global namespace //:: Operator void main() { int i = 10; { int i = 15; { int i = 17; printf("%d\n",i); //How to Access The Remaining i's here in c and c++ } } } //The above variables have to be defined at the above point

      C Offline
      C Offline
      Chris Losinger
      wrote on last edited by
      #2

      you can't. the global i hides all of the other i's. use different names. -c

      1 Reply Last reply
      0
      • S Santosh Rao

        #include int i = 7; //The above i can be accessed using the global namespace //:: Operator void main() { int i = 10; { int i = 15; { int i = 17; printf("%d\n",i); //How to Access The Remaining i's here in c and c++ } } } //The above variables have to be defined at the above point

        A Offline
        A Offline
        Alvaro Mendez
        wrote on last edited by
        #3

        In C you can only access the local i within your block of code (equal to 17). In C++ you can access the local i AND the global i (equal to 7). To access the global i, you'd use the scope resolution operator ( :: ) like this: printf("%d\n", ::i); Regards, Alvaro

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups