1)Global variable and Local variable- A) Global variables once declared they can be used any where in the program i.e. even in many functions. If possible u can use the global variables in the different user defined header files as like in packages in java. On the other hand global variables values can be changed programmatically
local variables are local to a functional and cant be used beyond that function.
2)Static variable and Global variable ? Static variables once declared they remain the same in the entire program. and those values cant be changed programatically.
1) Global variables scope is defined for the entire program, but local variables scope exists only for the block in which it is defined. 2) Any global variable can be accessed in the entire program, whereas the scope of the static variable is global, but can be modified only in the block in which it is defined. Static variables shields the variable to accessed by any other parts of the program.
And regarding the memory details global and static variables are created on heap by the compiler, but the local variables are created on stack. Source: CoolInterview.com
Global variable can access any where in the program whereas local variable can be accessed with in the function or method or with in the class. Static variable means the variable is static and it is having constant value which we had assigned a value for that static variable and we cannot change the value for static variable. Source: CoolInterview.com
Global, local and static are three different kind of variables.
Global variables are those which are defined globally and can be accessed anywhere in the program or outside the program. These are created in the heap area.
Local variables are those which are defined and accessed within the program or a particular method. Outside the program it cannot be accessed. these are created in the stack area.
Static variables are also created in the heap area. These are initialized only once in the program. If we declare a variable static at the declaration then it'll be automatically initialized to zero. Source: CoolInterview.com
1.Global variables can be accessed throughout the program but local variables only with in the function.Global variable life time is same as life time of program where as local variable life time is with in the function. Global variable are located in Data segment where as local variables are on stack. 2.Static variables are similar to global variables but their scope is limited to a file or a function in which they are declared an cannot be accessed from other files or function. They will be created at compile time not runtime. The location of static variable is in BSS segment. Source: CoolInterview.com
A variable carries a value.(already assigned OR from Scanf..what ever the way). I want to know whether the variable is positive or negative. Conditions: ----------- 1.NO looping logic should be used such as for ..while..etc.
2.should not use > or <.
3.should not use any numbers except 0. We can use 0 and equality operator. How to know the number is positive or negative?