in CO and Architecture retagged by
6,772 views
27 votes
27 votes

Match each of the high level language statements given on the left hand side with the most natural addressing mode from those listed on the right hand side.$$\begin{array}{clcl} \text{(1)} &\text{$A[I] = B[J]$} & \qquad\text{(a)} &\text{Indirect addressing} \\ 
\text{(2)} &\text{while $(^*A\text{++});$} & \qquad\text{(b)} & \text{Indexed addressing} \\   
\text{(3)} & \text{int temp $= ^*x$} & \qquad\text{(c)} &\text{Auto increment}  \\ \end{array}$$

  1. $(1, c), (2, b), (3, a)$
  2. $(1, c), (2, c), (3, b)$
  3. $(1, b), (2, c), (3, a)$
  4. $(1, a), (2, b), (3, c)$
in CO and Architecture retagged by
6.8k views

3 Comments

edited by

$\text{while(*A++)}$ tempted me to try the below code examples.

Note: $\text{A}$ is not an array but a pointer as $\text{A++}$ cannot be done with arrays because $\text{A++}$ is nothing but $\text{A=A+1}$ and in arrays value of $\text{A}$ is constant. But the same can be done with Pointers.

#include <stdio.h>
int main()
{
    int b[] = {3,2,0,1};
    int *A = b;
    //*A++ will be treated as *(A++) but increment of A will happen after using *A for condition check
    while(*A++){ 
        printf("%d\n",*A);    
    }
    return 0;
}
Output:
2
0

 

#include <stdio.h>
int main()
{
    int b[] = {3,2,0,1};
    int *A = b;
    //value of A[0] is checked for condition and then A[0] is incremented by 1, always checking A[0]
    while((*A)++){
        printf("%d\n",*A);    
    }
    return 0;
}
Output:
4
5
6
7
.
.
.

 

4
4

@jatinmittal199510 Sir,

output of the first code will be  :2,0,1.

why will it not print 1?

0
0

@Pranavpurkar This is because after *A = 0 is in while loop, it breaks out. Thus although later A++ makes it point to the 4th element (i.e. 1) it can’t print it.

0
0

1 Answer

38 votes
38 votes
Best answer

$C$ is the answer.

  • $A[i] = B[j]$;     Indexed addressing
  • while $(^*A++)$;      Auto increment
  • temp $=^*x$;       Indirect addressing
edited by
by

4 Comments

Cristine

Priority of post-increment/decrement is higher than dereferencing operator in C...

10
10

@akash.dinkar12 okay i got confused between *A++ and x=*A++ 

1
1

Priority of post increment/decrement operator is higher than dereference operator but Priority of pre increment/decrement operator and dereference operator is same.

Ref: https://en.cppreference.com/w/c/language/operator_precedence

2
2
Answer:

Related questions