Languages-C & C Plus Plus [TCS Placement]: Sample Questions 90 - 91 of 119

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 90

C & C Plus Plus

Question

MCQ▾

When are the global objects destroyed?

Choices

Choice (4)

a.

When the control comes out of the block in which they are being used.

b.

As soon as local objects die.

c.

When the program terminates.

d.

When the control comes out of the function in which they are being used.

Answer

c.

Explanation

  • Global variables exist for the whole program- when program terminates than global variables is destroyed.
  • Object outside all function bodies is known as global object.
  • Objects of classes outside any functions can be declared from anywhere in the program.
  • Such objects are globally available to all the function in the program.
  • Example:
  1. Classsample
  2. {
  3.     Intx;
  4.     Public:voidreadx() { cinx;}
  5. };
  6. Samples1; // global object
  7. Voidmain()
  8. {
  9.     Samples2; //local object
  10.     S1.readx();
  11. }

Question 91

C & C Plus Plus
Edit

Describe in Detail

Essay▾

What are the different storage classes in c?

Explanation

  • C has four types of storage: automatic, static , external and register
  • Variables having block scope and without static specifier have automatic storage allocation.
  • Variables with block scope, and with static specifier have static scope.
  • Global variables (i.e.. , file scope) with or without the static specifier also have static scope.
  • Memory obtained from calls to malloc () , alloc () or realloc () belongs to allocated storage class.
Given the Image is Define the Different Storage Classes in C

Developed by: