Why Global variable redefinition is not allowed?

user3721704
#include<stdio.h>

int i =0;
i=2;

int main(){

    // some Code here
    return 0;
}

Error : /Users/vaibhavkumar/Documents/C/primeFactors.c|4|error: redefinition of 'i'|

  1. Why redefinition of the variable is not allowed in C.
  2. Global variables are stored in Data Segment(area of memory), at the same place where static variables are stored. How came static variables can be redeclared ?
Clifford

That is not redefinition it is assignment.

Assignment is not the same as initialisation in C, and cannot be done outside a function - there is no thread of execution in that context, so when would it be done?

Variables with static linkage are no different to global variables (with extern linkage) in this respect, however static linkage variables are local to a single compilation unit and are not visible externally. If you declare two statics of the same name in separate compilation units, they are entirely independent and unrelated variables - they needn't even be the same type.

Note that static linkage is distinct from static storage, but they use the same keyword. All global and static linkage variables have static storage class implicitly, but a function local variable declared static has static storage class - i.e. it always exists - like a global, but is only visible locally.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

C++: Redefinition of global variable

From Dev

C++ redefinition of variable, global namespace polluted and I don't know why

From Dev

C++ allows redefinition of global (const) variable?

From Dev

Is variable identifier allowed on global replace?

From Dev

Local variable is allowed the same name as global variable?

From Dev

Redefinition of a pointer in global scope

From Dev

Why is variable declaration not allowed here?

From Dev

Avoid redefinition preprocessor variable

From Dev

Redefinition of a variable Error

From Dev

Python variable redefinition in a function

From Dev

Not sure why global variable is not changing

From Dev

Why fsize variable is cleared if global?

From Dev

Why is variable not global in BGE Python

From Dev

Why is NaN a global variable in JavaScript?

From Dev

Why a variable defined global is undefined?

From Dev

Why is my global variable null?

From Java

Why type alias is allowed as name of variable?

From Dev

Why is jumping across variable definitions (with goto) allowed?

From Java

Why is a JavaScript reserved keyword allowed as a variable name?

From Dev

Why are multi-variable return statements allowed?

From Dev

Why are special characters not allowed in variable names?

From Dev

Why is a JavaScript reserved keyword allowed as a variable name?

From Dev

Why is jumping across variable definitions (with goto) allowed?

From Dev

Why are global methods allowed to be defined outside of a class in Ruby?

From Dev

Why is a global variable called when there is a local variable?

From Dev

Redefinition; previous definition was 'data variable'

From Java

CORE::GLOBAL::die redefinition inside BEGIN

From Dev

Why returning a member variable using "this" pointer is not allowed, but setting a member variable using "this" is allowed?

From Dev

Why does not global variable hold value

Related Related

  1. 1

    C++: Redefinition of global variable

  2. 2

    C++ redefinition of variable, global namespace polluted and I don't know why

  3. 3

    C++ allows redefinition of global (const) variable?

  4. 4

    Is variable identifier allowed on global replace?

  5. 5

    Local variable is allowed the same name as global variable?

  6. 6

    Redefinition of a pointer in global scope

  7. 7

    Why is variable declaration not allowed here?

  8. 8

    Avoid redefinition preprocessor variable

  9. 9

    Redefinition of a variable Error

  10. 10

    Python variable redefinition in a function

  11. 11

    Not sure why global variable is not changing

  12. 12

    Why fsize variable is cleared if global?

  13. 13

    Why is variable not global in BGE Python

  14. 14

    Why is NaN a global variable in JavaScript?

  15. 15

    Why a variable defined global is undefined?

  16. 16

    Why is my global variable null?

  17. 17

    Why type alias is allowed as name of variable?

  18. 18

    Why is jumping across variable definitions (with goto) allowed?

  19. 19

    Why is a JavaScript reserved keyword allowed as a variable name?

  20. 20

    Why are multi-variable return statements allowed?

  21. 21

    Why are special characters not allowed in variable names?

  22. 22

    Why is a JavaScript reserved keyword allowed as a variable name?

  23. 23

    Why is jumping across variable definitions (with goto) allowed?

  24. 24

    Why are global methods allowed to be defined outside of a class in Ruby?

  25. 25

    Why is a global variable called when there is a local variable?

  26. 26

    Redefinition; previous definition was 'data variable'

  27. 27

    CORE::GLOBAL::die redefinition inside BEGIN

  28. 28

    Why returning a member variable using "this" pointer is not allowed, but setting a member variable using "this" is allowed?

  29. 29

    Why does not global variable hold value

HotTag

Archive