3i Infotech Papers: Sample Questions 979 - 980 of 1245

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

Question number: 979

» Languages » C & C Plus Plus

Essay Question▾

Describe in Detail

How can you increase the size of a dynamically allocated array?


Dynamically allocatng arrays(2D).

Dynamically Allocatng Arrays (2D).

Dynamically allocatng arrays (2D).

  • In C, Malloc allocates new memory space of size “newsize” to the pointer variable “ptr” and returns a pointer to the first byte of the new memory block.

  • The new size may be smaller or large than original size, it returns a NULL pointer and the original block is freed

  • If the function is unsuccessful in allocating additional space

  • Subsequently memcpy (memory copy) function can be used to copy the contents from old location to new location.

  • C++ memory allocation using “new” is allocated below.

Program in C++ (Using New to Allocated Memory):

  1. int main()
  2. {
  3.     stringname = NULL;
  4.     name = new string[1];
  5.     name[0] = "Mike";
  6.     cout << name[0] << endl;
  7.     delete [] name;
  8.     name = new string[3];
  9.     name[0] = "Mike";
  10.     name[1] = "Steve";
  11.     name[2] = "Dave";
  12.     cout << name[0] << endl;
  13.     cout << name[1] << endl;
  14.     cout << name[2] << endl;
  15.     delete [] name;
  16.     while (_kbhit() == 0);
  17.     return 0;
  18. }

Question number: 980

» Basic CS » Operating System



Semaphore is used for


Choice (4) Response




dead-lock avoidence




Question does not provide sufficient data or is vague




Understanding of semaphore.

Understanding of Semaphore.

Understanding of semaphore.

  • Semaphore is a simple variable used which uses critical sections to achieve process synchronization in a multi-processing environment.

  • Two common semaphores are:

    • Counting semaphore which takes non-negative integer values

    • Binary semaphore which takes the value .

  • If semaphores are implemented using file descriptors. Semaphore creations are not atomic. Thus if two processes try to create, initialize and use a semaphore at the same time, a race condition is created.

  • They are thus implemented through interrupts or by using test-set operations to achieve atomicity