TCS Papers: Sample Questions 353 - 355 of 502

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

Question number: 353

» Languages » C & C Plus Plus

Short Answer Question▾

Write in Short

How do you find out if a linked-list has an end (i. e. the list is not a cycle)

Explanation

  • You can find out by using 2 pointers.

  • One of them goes 2 nodes each time.

  • The second one goes at 1 node every time.

  • If there is a cycle, the one that goes 2 nodes each time will eventually meet the one that goes slower.

Question number: 354

» Languages » C & C Plus Plus

MCQ▾

Question

Which of the following is the correct class of the object cout?

Choices

Choice (4) Response

a.

Ifstream

b.

Istream

c.

Iostream

d.

Ostream

Answer

d.

Explanation

  • Ostream is the correct class of the object cout.

  • This c++ class is used for outputting information to an arbitrary device (screen, hard drive, diskette. . ) from a program.

  • C++ always has an instantiated object of class ostream called “cout”

The ostream class

The Ostream Class

Given the image is define the ostream class

Question number: 355

» Basic CS » Operating System

Essay Question▾

Describe in Detail

What is a binary semaphore? What is its use?

Explanation

  • A binary semaphore takes only as values.

  • They are used to implement mutual exclusion and synchronize concurrent processes.

  • It can be used for guarding critical section and also for guarding single resource.

  • To show the usage of binary semaphore, we are going to implement a print queue that can be used by concurrent tasks to print their jobs.

  • This print queue will be protected by a binary semaphore, so only one thread can print at a time.

  • Semaphore value 1 indicates, resource is available, 0 means it is not available.

Image of The Binary semaphore

Image of the Binary Semaphore

Given the image is defining the binary semaphore.