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. General Programming
  3. C / C++ / MFC
  4. If the data is static, how can you access that data in another file ?

If the data is static, how can you access that data in another file ?

Scheduled Pinned Locked Moved C / C++ / MFC
question
4 Posts 2 Posters 0 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.
  • K Offline
    K Offline
    krish_kumar
    wrote on last edited by
    #1

    Hello Question : Differentiate static and extern ? If the data is static, how can you access that data in another file ? My answer is : The static keyword allows a variable to maintain its value among different function calls. Extern says the variable, or function, is defined outside this source file. main.h -------- #include <> static int x; main.c -------- #include "main.h" int main(void) { printf("\n x is %d", x); return 0; } My answer is sufficient or partially or wrong ...? Give me an advise ? Thanking you.

    C 1 Reply Last reply
    0
    • K krish_kumar

      Hello Question : Differentiate static and extern ? If the data is static, how can you access that data in another file ? My answer is : The static keyword allows a variable to maintain its value among different function calls. Extern says the variable, or function, is defined outside this source file. main.h -------- #include <> static int x; main.c -------- #include "main.h" int main(void) { printf("\n x is %d", x); return 0; } My answer is sufficient or partially or wrong ...? Give me an advise ? Thanking you.

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

      its partially correct. 'static' has multiple meanings. you've mentioned one, but there is another meaning that is more closely related to 'extern'.

      image processing toolkits | batch image processing

      K 1 Reply Last reply
      0
      • C Chris Losinger

        its partially correct. 'static' has multiple meanings. you've mentioned one, but there is another meaning that is more closely related to 'extern'.

        image processing toolkits | batch image processing

        K Offline
        K Offline
        krish_kumar
        wrote on last edited by
        #3

        Could you elaborate it , please?

        C 1 Reply Last reply
        0
        • K krish_kumar

          Could you elaborate it , please?

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

          http://lmgtfy.com/?q=static+function+C[^]

          image processing toolkits | batch image processing

          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