TCS Papers: Sample Questions 389 - 390 of 502

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

Question number: 389

» Languages » C & C Plus Plus

Essay Question▾

Describe in Detail

Which of the following standard C library converts a string to a long integer and reports any leftover numbers that could not be converted.


  • strtol () converts a string to a long integer and reports any leftover numbers that could not be converted.

  • function long int strtol (const char * str, char **endptr, int base) converts the initial part of the string in str to a long int value according to the given base, which must be between 2 and 36 inclusive, or be the special value 0.

  • This function returns the converted integral number as a long int value, else zero value is returned.

  • Example:

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. int main () {
  4.     char str[30] = "123456 This is example";
  5.     char *ptr;
  6.     long ret;
  7.     ret = strtol(str, &ptr10);
  8.     printf("The number is %ld "ret);
  9.     printf("String part is |%s|"ptr);
  10.     return(0);
  11. }
  • Output:

The number is 123456

String part is|This is example|

Question number: 390

» Basic CS » Operating System

Essay Question▾

Describe in Detail

What is time-stamping?


  • A timestamp is the current time of an event that is recorded by a computer.

  • It is a technique proposed by Lamport, used to order events in a distributed system without the use of clocks.

  • This scheme is intended to order events consisting of the transmission of messages.

  • Through mechanisms such as the Network Time Protocol (NTP), a computer maintains accurate current time, calibrated to minute fractions of a second.

  • Such precision makes it possible for networked computers and applications to communicate effectively.

  • The timestamp mechanism is used for a wide variety of synchronization purposes, such as assigning a sequence order for a multi-event transaction so that if a failure occurs the transaction can be voided.

  • Another way that a timestamp is used is to record time in relation to a particular starting point. In IP telephony.

  • Example: the Real-time Transport Protocol assigns sequential timestamps to voice packets so that they can be buffered by the receiver, reassembled, and delivered without error.

  • When writing a program, the programmer is usually provided an application program interface for a timestamp that the operating system can provide during program execution.

  • Each system ‘i’ in the network maintains a counter Ci.

  • Every time a system transmits a message, it increments its counter by 1 and attaches the time-stamp Ti to the message.

  • When a message is received, the receiving system ‘j’ sets its counter Cj to 1 more than the maximum of its current value and the incoming time-stamp Ti.

  • At each site, the ordering of messages is determined by the following rules: For messages x from site i and y from site j, x precedes y if one of the following conditions holds

    1. if Ti < Tj or

    2. if Ti = Tj and i < j.

Image of Timestamping

Image of Timestamping

Given the image is define the timestamp concurrency control protocols