3i Infotech Papers: Sample Questions 587 - 588 of 1245

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

Question number: 587

» Languages » C & C Plus Plus

Essay Question▾

Describe in Detail

Differentiate between declaration and definition in c++.

Explanation

  • A declaration introduces a name into the program while a definition provides a unique description of an entity (e. g. type, instance, and function).

  • Declarations can be repeated in a given scope if they introduce the same name in a given scope but there must be exactly one definition of every object, function or class used in a C++ program.

  • A declaration is a definition unless it

    • Declares a function without specifying its body

    • Contains an extern specifier and no initializer or function body

    • Is the declaration of a static class data member without a class definition

    • Is a class name definition

    • Is a typedef declaration

  • A definition is declaration unless it:

    • Defines a static class data member,

    • Defines a non-inline member function.

Question number: 588

» Languages » C & C Plus Plus

Essay Question▾

Describe in Detail

When can you tell that a memory leak will occur?

Explanation

  • A memory leak occurs when a program cannot free a block of dynamically allocated memory.

  • When program creates memory using constructor but fails to call destructor for release or free- causing memory leakage

  • Programmers allocate memory in heap and forget to delete it. Memory on stack is automatically managed.

  • Memory leaks are serious for programs like deamons and servers which never terminate.

Image of the memory leak

Image of the Memory Leak

Given the image is function with memory leak