ANSWERS: 7
  • sorry i have no idea!
  • A global variable in C/C++ is a variable which can be accessed from any module in your program. You can define a global variable with a statement like this: int myGlobalVariable; This allocates storage for the data, and tells the compiler that you want to access that storage with the name 'myGlobalVariable'. But what do you do if you want to access that variable from another module in the program? You can't use the same statement given above, because then you'll have 2 variables named 'myGlobalVariable', and that's not allowed. So, the solution is to let your other modules DECLARE the variable without DEFINING it: extern int myGlobalVariable; This tells the compiler "there's a variable defined in another module called myGlobalVariable, of type integer. I want you to accept my attempts to access it, but don't allocate storage for it because another module has already done that".
    • Wenso
      Useful info...thanks for sharing the post..
  • variables global and extern,are both initialized to zero??
  • variables global and extern,are both initialized to zero??
  • An extern is not actually a variable. It's a declaration that tells the c pre processor and assembler that the linker will resolve the extern to a variable that's declared in another module. If the extern isn't a standard type, the type must be declared in an include file so the pre processor will accept and the assembler will know how to align the variable. You may want to understand a bit more about multi-pass compilers, which is what c and c++ are, to better understand this.
  • EXTREN VARIABLE In the C and C++ programming languages, an external variable is a variable declared with the keyword extern. There are two specific meanings to extern, which are dependent on context. When applied to the declaration of a variable, extern tells the compiler that said variable will be found in the symbol table of a different translation unit. This is used to expose variables in one implementation file to a different implementation file. The external declaration is not resolved by the compiler, but instead by the linker, meaning that extern is a legitimate mechanism to install modularity at the compiler level. GLOBAL VARIABLE Global variables are used extensively to pass information between sections of code that don't share a caller/callee relation like concurrent threads and signal handlers. Languages where each file defines an implicit namespace eliminate most of the problems seen with languages with a global namespace though some problems may persist without proper encapsulation. Without proper locking code using global variables will not be thread-safe except for read only values in protected memory.
  • when a variable is declared before main it is global,but cannot be used in any other file by including the program as a header file.where as an extern variable can be used in other file by including it as header file...

Copyright 2023, Wired Ivy, LLC

Answerbag | Terms of Service | Privacy Policy