Languages [TCS Placement]: Sample Questions 70 - 72 of 131

Get unlimited access to the best preparation resource for competitive exams : get questions, notes, tests, video lectures and more- for all subjects of your exam.

Question 70

Edit

Write in Short

Short Answer▾

Is it possible to initialize a variable at the time it was declared?

Explanation

  • Yes, a separate assignment statement is not required after the variable declaration, unless value is changed later on.
  • For example: char planet [15] = “Earth” does two things:
    • Declares a string variable named planet
    • Initializes it with the value “Earth” .

Question 71

Edit

Describe in Detail

Essay▾

Write a function to swap the values of two integers.

Explanation

Program:

  1. #include<stdio.h>
  2. intmain()
  3. {
  4.     intx=15, y=20;
  5.     x=x+y;
  6.     y=x-y;
  7.     x=x-y;
  8.     printf(“Afterswapping :x=%d, y=%d”, x, y);
  9.     return0;
  10. }
  • Output:

After swapping: x = 20, y = 15

Question 72

Edit

Describe in Detail

Essay▾

State the differences between the Dispose () and Finalize () .

Explanation

CLR uses the Dispose and Finalize methods to perform garbage collection of run-time objects of . NET applications.

Difference between the Dispose () and Finalize ()
Finalize ()Dispose ()
The Finalize method is called automatically by the runtime.The Dispose method is called by the programmer.
CLR has a garbage collector (GC) , which periodically checks for objects in heap that are no longer referenced by any object or program.Dispose is another method to release the memory used by an object. The Dispose method is explicitly called in code to dereference an object from the heap.
It calls the Finalize method to free the memory used by such objects.Dispose method can be invoked only by the classes that implement the IDisposable interface.
Can be used to free unmanaged resources like files, database connections etc. held by an object before that object is destroyed.Used to free unmanaged resources like files, database connections etc. at any time.
Implemented with the help of destructor in C ++ & C#.Implemented by IDisposable interface Dispose () method.

Developed by: