edited by
16,830 views
54 votes
54 votes

Consider the following snippet of a C program. Assume that swap $(\&x, \&y)$ exchanges the content of $x$ and $y$:

int main () {
    int array[] = {3, 5, 1, 4, 6, 2};
    int done =0;
    int i;
    while (done==0) {
        done =1;
        for (i=0; i<=4; i++) {
            if (array[i] < array[i+1]) {
                swap(&array[i], &array[i+1]);
                done=0;
            }
        }
        for (i=5; i>=1; i--) {
            if (array[i] > array[i-1]) {
                swap(&array[i], &array[i-1]);
                done =0;
            }
        }
    }
    printf(“%d”, array[3]);
}

The output of the program is _______

edited by

7 Answers

0 votes
0 votes
After the run of first loop the second loop is never gonna run , avoid the silly mistake and mark the answer 3 :)
Answer:

Related questions

30 votes
30 votes
11 answers
1
Madhav asked Feb 14, 2017
9,550 views
Consider the following function implemented in C:void printxy(int x, int y) { int *ptr; x=0; ptr=&x; y=*ptr; *ptr=1; printf(“%d, %d”, x, y); }The output of invoking $...
36 votes
36 votes
6 answers
2
26 votes
26 votes
3 answers
3
khushtak asked Feb 14, 2017
5,768 views
Match the following:$$\begin{array}{|ll|ll|}\hline P. & \text{static char var ;} & \text{i.} & \text{Sequence of memory locations to store addresses} \\\hline Q. & \text...
41 votes
41 votes
4 answers
4
Arjun asked Feb 14, 2017
20,976 views
A message is made up entirely of characters from the set $X=\{P, Q, R, S, T\}$. The table of probabilities for each of the characters is shown below:$$\begin{array}{|c|c|...