3i Infotech Papers: Sample Questions 888 - 890 of 1245

Examrace Placement Series prepares you for the toughest placement exams to top companies.

Question number: 888

» Languages » C & C Plus Plus

Short Answer Question▾

Write in Short

What are the advantages using pointers in a program?


  • Provide in-out variables- Function cannot return more than one value but it can modify many pointer variables as if it is returning more than one variable.

  • Allows performing dynamic memory allocation and deallocation- we can decide the size of the “array” at runtime by allocating the necessary space.

  • Pointers provide direct access to memory.

  • Enable complex data structures like linked list, stack, queues, trees, graphs etc.

  • Allow resizing the dynamically allocated memory block.

  • Addresses of objects can be extracted using pointers- allowing dangerous but otherwise impossible manipulations.

Question number: 889

» Languages » C & C Plus Plus

Short Answer Question▾

Write in Short

What is the difference between an enumeration and a set of pre-processor # defined?


Define types of enumerated data type.

Define Types of Enumerated Data Type.

Define types of enumerated data type.

  • Enumeration provide convenient way to associate constant values with names, an alternative to # define with advantage that the values are based on types.

  • Variables of enum types are checked by compilers, and hence are better variables.

Question number: 890

» Languages » C & C Plus Plus

Essay Question▾

Describe in Detail

What are the different storage classes in C?


Image of the storage class

Image of the Storage Class

Image of the storage class

C language uses 4 storage classes:

  • Auto:

    • Default storage class for all the variables declared inside a function or a block.

    • Rarely used while writing programs in C language.

    • Auto variables only exist within their scope- that is in the function they are declared and not outside them.

    • Memory is allocated on stack

  • Extern:

    • Extern storage class variables are defined elsewhere, and not within the same block they are used.

    • Main purpose is to use variables across two different files part of a large program.

  • Static:

    • Static variables preserve their value even after they are out of their scope.

    • Preserve the value of their last use in their scope.

    • Memory is allocated on heap because they are not re-declared.

    • Assigned the value 0 by the compiler.

  • Register:

    • Declares register variables with similar scope and functionality as auto variables.

    • Only difference is that it provides complier hint to store variables in the register of the microprocessor if space is available.

    • Note that this is just a hint and not a guarantee.

    • We cannot obtain the address of a register variable using pointers.