----- Original Message ----- 
From: "vibhor garg" 
To: 
Sent: Monday, April 12, 2004 1:19 AM
Subject: [C-Guru] answer plz

> can anyone here answer these questions
> 
> 1)What is static identifier? 

The `static' specifier has various meanings depending on where it appears.

*   If the `static' storage class specifier appears at the file scope, the 
        identifier (an object or function) has internal linkage.

*   The object having the static storage class has following few properties:

        +   Storage is reserved, and initialized prior to program startup.  
        +   If the object is in a block scope, it retains its last-stored
            value throughout the execution of the entire program.

*   Following are specific to C99:
        
        +   If a compound literal occurs outside a function, then it has
            static storage class.  
        +   C99 adds another meaning to the `static' specifier.  The following
            declaration,
                
                void mango ( char a[static 3] );

            guarantees that the pointer "a" (pointing to the first element of
            an array) points to an array containing at least 3 elements.  It 
            also guantees that "a" is non-NULL.

    See also question 49 of my FAQ page.
            

> 2)Where are the auto variables stored? 

Generally, they are stored in a stack local to the running program.  As far as
I know, the Standard does not mention where the local variables should go. 
See question 11 of my FAQ page, however.

> 3)Where does global, static, local, register        
> variables, free memory and C Program instructions get
> stored? 

*   These are all implementation defined.  Access to `register' specified 
            indentifiers should be as fast as possible, so the compiler may
            place the value in a machine register.  However, the compiler is
            free to treat a `register' declaration as an `auto' declaration.

*   For local and static see, question 11 of my FAQ page.  

*   Where free memory is maintained is an OS specific concept.  Instructions
    are generally stored in code segement.

> 4)Difference between arrays and linked list? 

Pass.

> 5)What are enumerations? 

This is best explained in the K&R section A.8.4, Enumerations.

> 6)What are register variables? What are the advantage
> of using register variables? 

*   See the answer to question 3 above.
*   Note the following properties of register storage class:

        +   An array should not be declared with register storage class; doing 
            so is an undefined behavior.

        +   Address-of operation(&) can not be applied to an identifier with
            register storage class.

        +   `register' storage class is the only class that can appear in a
            parameter declaration.

        +   The `register' specifier should not occur in an external 
            declaration.

> 7)What is the use of typedef? 

This is best explained in the K&R section 6.7, Typedef.  

> 8)Out of fgets() and gets() which function is safe to
> use and why? 

fgets() is always safe to use since gets() does not check for boundry limits.
gets() may overwrite the buffer.

> 9)Difference between strdup and strcpy? 

One big difference is strudup() a non-standard function, whereas strcpy() is a 
standard function.  

> 10)In header files whether functions are declared or defined?  

*   They are declared, not defined.  The functions declared in a header file are
            defined in a specific library, and later linked with the application
            program.  

> 11)What are macros? what are its advantages and disadvantages? 

*   Few advantages are listed without much explanations:
        
        +   In some situations, macros can be used instead of functions.  Since,
            macros expands into its place of calling, it avoids function call
            overhead.

        +   Macros are used for writing portable code using #if, #ifdef, #ifndef
            and #endif.

            (There are many others)

*   Disadvantages are:

        +   Unwanted side effects, as in

                #define SQUARE(x) x*x

        +   Increase in code size if a substitue macro for a function is used
            heavily.

    Source: geocities.com/vijoeyz/faq/c

               ( geocities.com/vijoeyz/faq)                   ( geocities.com/vijoeyz)