EmbLogic's Blog

datatype….

will anyone suggest me the difference b/w-
int flag;
const int flag;
static int flag;

3 Responses to datatype….

  1. kamran says:

    int flag;
    flag is an integer type and can take possible value that are within the limits of the integer scope as per the definition.

    const int flag;
    flag is an integer type and the value of flag will be const and can not be changed, in other words : A constant is a variable that cannot be changed in value.

    static int flag;

    A static is a variable that cannot be used outside the scope of it’s declaration. That is, if it is a global variable then it can only by used in the file that declares it. If it is a variable inside a function, then it can be use only inside that function.

  2. m.siddarth says:

    The storage class, static, similarly provides a lifetime over the entire program, however; it provides a way to limit the scope of such variables, Static storage class is declared with the keyword static as the class specifier when the variable is defined. These variables are automatically initialized to zero upon memory allocation just as external variables are. Static storage class can be specified for automatic as well as external variables.

    Static automatic variables continue to exist even after the block in which they are defined terminates. Thus, the value of a static variable in a function is retained between repeated function calls to the same function. The scope of static automatic variables is identical to that of automatic variables, i.e. it is local to the block in which it is defined; however, the storage allocated becomes permanent for the duration of the program. Static variables may be initialized in their declarations; however, the initializers must be constant expressions, and initialization is done only once at compile time when memory is allocated for the static variable.

  3. yeah ,sidharth sir said right
    what i want to commenting on const int
    its not constant like as preprocessor constants
    we can change its value by using pointers.so always use define when u work with pointers.

Leave a Reply to kamran Cancel reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>