Languages-C & C Plus Plus [3i Infotech Placement]: Sample Questions 29 - 31 of 354

Glide to success with Doorsteptutor material for competitive exams : get questions, notes, tests, video lectures and more- for all subjects of your exam.

Question 29

C & C Plus Plus
Edit

Write in Short

Short Answer▾

What are the advantages using pointers in a program?

Explanation

  • 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 30

C & C Plus Plus
Edit

Write in Short

Short Answer▾

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

Explanation

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 31

C & C Plus Plus
Edit

Describe in Detail

Essay▾

What are the different storage classes in C?

Explanation

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.

Developed by: