3i Infotech Papers: Sample Questions 181  182 of 1245
Examrace Placement Series prepares you for the toughest placement exams to top companies.
Question number: 181
Describe in Detail
void main ()
{
char * s = “12345s ”;
printf ( “%d”, sizeof (s) );
}
Explanation

In the progam
char * s = “12345s ”; 

printf (“%d”, sizeof (s) ); 


For a 32 bit computer, the pointer size is 4 bytes

64 bit computers have 8 byte pointer size, however, a 64bit computer running a 32bit OS will have 4 byte pointer.

Thus, under a specific architecture, all types of pointers (void*, int*, char*, long * etc) will have same size (except function pointers).
Question number: 182
Describe in Detail
What is your favourite sorting algorithm? Why?
Explanation

Bubble sort is a good simple algorithm.

Not suitable for large data sets as its average and worstcase complexity are of where n is the number of items.

Beautiful algorithm easy to visualize with sorted elements bubbling up.
Bubble sort:

Let’s solve unsorted array:

1^{st} Iteration:

Start with two elements, comparing them to check which one is greater.

Value 33 is greater than 14

Therefore, they are in sorted locations.

We compare 33 with 27.

New array looks like

Compare 33 and 35.

Both are in sorted positions.

The next two values, 35 and 10

10 is smaller then 35 and hence are not sorted.

Swap values.

We find that we reached the end of the array.

We are showing how an array should looks like each iteration. One iteration brought 35 to its correct location it bubbled to the top

After the second iteration.

After each iteration, one value moves to correct position.

When no swap is required, bubble sort learns that array is completely sorted.