# 3i Infotech Papers: Sample Questions 741 - 742 of 1245

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

## Question number: 741

Essay Question▾

### Describe in Detail

What is the output of the following program?

1. `main ()`
2. `{`
3. `    char * p = “GOOD” ;`
4. `    char a[ ] = “GOOD” ;`
5. `    printf ( “  sizeof (p) = %d, sizeof ( * p) = %d, strlen (p) = %d” sizeof (p), sizeof ( * p), strlen (p) );`
6. `    printf ( “  sizeof (a) = %d, strlen (a) = %d” ,sizeof (a), strlen (a) );`
7. `}`

### Explanation

Size of (p) = 2, size of (*p) = 1, strlen (p) = 4 size of (a) = 5, strlen (a) = 4

In the program

 char * p = “GOOD”; Given the character pointer p=”GOOD” char a [] = “GOOD”; Given the character array a printf (“ sizeof (p) =%d, sizeof (* p) =%d, strlen (p) =%d” sizeof (p), sizeof (* p), strlen (p) ); Here sizeof (p) = > izeof (char*) = > 2 sizeof (*p) = > izeof (char) = > 1 When sizeof operator is applied to an array it returns the sizeof the array and it is not the same as the sizeof the pointer variable printf (“ sizeof (a) =%d, strlen (a) =%d”, sizeof (a), strlen (a) ); sizeof (a) = > size of the character array = > 5 here the sizeof (a) where a is the character array and the size of the array is 5 because the space necessary for the terminating NULL character should also be taken into account

## Question number: 742

### Write in Short

What is a binary semaphore? What is its use?

### Explanation

• Binary semaphores are binary- can take only two values.

• “1” might represent a process is in the critical section and other should wait, the other indicating the critical section is free.

• Sometime easier to implement than counting semaphore.

• Binary semaphore are used as mutex locks, to implement mutual exclusion and synchronize concurrent processes.