C Questions

Preprocessor
  1. What is preprocessor command?

    A preprocessor is a text substitution tool and it tells to compiler to do required pre-processing before the actual compilation.
    All preprocessor commands begins with hash symbol(#).

  2. What is header file?

    A header file is a file with extension .h which contains C function declarations and macro definitions to be shared between several source files.

  3. What is the default header file that comes with the C compiler?

    stdio.h

  4. What is the difference between #include<filename> and #include "filename"?

    #include<filename> - It searches directories at pre-designated by the compiler.
    #include "filename" - It searches in the same directory as the file containing the directive.

main() function
  1. Define main() function?

    main() is a compiler declared function whose defined by the user, which is invoked automatically by the operating system when program is being executed.

  2. What is the default prototype of main() function?

    Default return of a main() function is int and default parameter is void.
    int main(void){
        //body
        return 0;
    }

  3. What are the arguments of main() function?

    int main(int argc, char *argv[], char * env[]){
        //body
        return 0;
    }
    A main() function has 3 arguments:

    1. argc (Argument Count) - Stores number of command-line arguments passed by the user including the name of the program.
    2. argv (Argument Vector) - It is an array of strings which stores values which are passed from command-line.
    3. env (Environment Vector) - It contains all environmental variables of the system.
  4. What is the use of return statement in main() function?

    A return statement in main() function tells to compiler about type of termination. The return value is 0(zero) means normal termination and return value is non-zero means abnormal termination.

  5. Is it possible to execute user defined functions before and after main() function in C?

    #include<stdio.h>
    void before_main();
    void after_main();
    #pragma startup before_main
    #pragma exit after_main
    void before_main(){
        printf("Before main() function.\n");
    }
    void after_main(){
        printf("After main() function.\n");
    }
    int main(){
        printf("Inside main() function.\n");
        return 0;
    }
    Note:The above code executes in Turbo C compiler, doesn't in GCC compiler.

Storage Classes
  1. What is Storage Class?

    In a C programming, storage classes are used to define the storage area and visibility of a variable.

  2. How many types of storage classes?

    In C, there are four types of storage classes:

    • auto - stored in stack area and can be accessed within the block where it is declared, whose initial value is garbage value.
    • extern - stored in data segment area and can be accessed throughout the program, whose initial value is zero.
    • static - stored in data segment area and can be accessed within the block where it is declared, whose initial value is zero.
    • register - stored in CPU register and can be accessed within the block where it is declared, whose initial value is garbage value.
Data Types
  1. Difference between %f, %e and %g?

    %f - represents the floating-point data, it takes upto 6 decimal points.

    %e - represents the data in scientific format or exponential power.

    %g - represents the data like %f and %e but removes succeeding zeros.

  2. Difference between type conversion and type casting?

    • Type Conversion: The data is converted from one data type to another data type by the compiler at compile time.
    • Type Casting: The data is converted from one data type to another data type by the programmer using casting operator ().
Control Statements
  1. What is the default conditional value in for loop?

    true

  2. What is entry controlled and exit controlled loops?

    • Entry Controlled Loop: Loops are first check the condition and entering into the loop are entry controlled loops. Eg. while and for are entry controlled loops.
    • Exit Controlled Loop: Loops are first executing the body of the loop and then checked the condition are exit controlled loops. Eg. do-while is exit controlled loops.
Arrays
  1. Define an Array?

    An Array is a collection of similar type of elements stored in a sequential memory locations.

  2. What is meant by base address of an Array?

    Address of first element in the Array is known as Base address.

  3. Assume ary is an array variable contains 5 elements. What is the difference between ary[1] and *(ary+1).

    Both ary[1] and *(ary+1) accessed element present in 1st indexed position.

Pointers
  1. Define Pointer?

    A pointer is a variable which stores address(memory location) of another variable.

  2. What is pointer to pointer

    Pointer to pointer means a pointer stores address of another pointer.

  3. Define void pointer?

    A pointer stores address of any of variable is called void pointer.

  4. What is wild pointer?

    An uninitialized pointers are known as wild pointers.

  5. What is dangling pointer?

    A pointer points to memory location that already deleted is known as dangling pointer.

  6. What is NULL pointer

    A pointer doesn't points to any memory location and initialized with NULL value is known as NULL pointer.

  7. What is the size of pointer?

    In 64-bit compiler, size of pointer is 8 bytes.
    In 32-bit compiler, size of pointer is 4 bytes.
    Note: Remember size of pointer doesn't depends on datatype. Its depends on operating system and its architecture.

  8. What are the advantages of pointers>

    • Using pointers we can accessing memory location.
    • With pointers we dynamically allocate and deallocate memory.
Structures and Unions
  1. Define Structure?

    A structure is a collection of elements of different datatypes. Each element in a structure is called member.

  2. Define Union?

    Union is also a collection of elements of different datatypes stored in same memory location.

  3. Difference between structures and unions

    Structures Unions
    struct keyword is used to define structures. union keyword is used to define unions.
    Size of structure is "sum of sizes of individual data members of structure". Size of union is "size of largest data members of union".
    In structures, every data members has its own memory location. In unions, all data members shares same memory location which means at a time only one data is stored.
  4. Define self-referential structure?

    Self-referential structure is structure that points to the same structure.

Functions
  1. Define function?

    A function contains set of statements enclosed in curly braces {}.

  2. What is meant by prototype of function?

    Prototype of a function is nothing its return type.

  3. What is the default return type of user-defined function?

    int

  4. In how many we call a function?

    Two ways: Call by Value and Call by Reference.

  5. Difference between actual parameters and formal parameters

    Actual parameters are the values passed when function calling.
    Formal parameters are the variables that are declared at function definition to store values.

  6. Define Recursion?

    A function calls itself is known as recursion.

No comments:

Post a Comment

Total Pageviews