3i Infotech Placement: Sample Questions 1167 - 1168 of 1245

Glide to success with Doorsteptutor material for competitive exams : get questions, notes, tests, video lectures and more- for all subjects of your exam.

Question 1167

Edit

Describe in Detail

Essay▾

What is a semaphore?

Explanation

Understanding of Semaphore
  • A semaphore controls access by multiple processes to a common resource in a parallel programming environment.
  • Widely used to control access to files and shared memory.
  • Functionalities associated with semaphores are set, check and wait until it clears to set it again.
  • The two most common kinds of semaphores are counting semaphores and binary semaphores.
  • Counting semaphores take non-negative integer values and binary semaphore can take the value only.
  • Semaphores are commonly used for two purposes: to share a common memory space and to share access to files.

Question 1168

Edit

Describe in Detail

Essay▾

What is the output of the following program?

  1. typedefstructerror { intwarning, error, exception; }error;
  2. main ()
  3. {
  4.     errorg1;
  5.     g1. error =1;
  6.     printf ( “%d” ,g1. error);
  7. }

Explanation

In the program three usages of name “error” are distinguishable by the compiler at any instance, hence are valid (they are in different namespaces) .

Table Shows the Program
Typedef struct error {int warning, error, exception;} error;
  • This “error” can be used only by preceding the error by struct keyword as in:

    struct error someError;

    typedef struct error {int warning, error, exception;} error;

  • This can be used only after. (dot) or ⇾ (arrow) operator preceded by the variable
g1. error = 1;

printf ( “% d” , g1. error) ;

  • typedef struct error {int warning, error, exception;} error;
  • This can be used to define variables without using the preceding struct keyword as in:
  • error g1;
  • Since the compiler can distinguish between these three usages, it is legal and valid.

Note: This code is given here to just explain the concept. In real programming don՚t use such overloading of names. It reduces the readability of the code.

Developed by: