retagged by
3,961 views
10 votes
10 votes

What is the output in a $32$ bit machine with $32$ bit compiler?

#include<stdio.h>
rer(int **ptr2, int **ptr1)
{
    int *ii;
    ii=*ptr2;
    *ptr2=*ptr1;
    *ptr1=ii;
    **ptr1*=**ptr2;
    **ptr2+=**ptr1;
}
void main(){
    int var1=5, var2=10;
    int *ptr1=&var1,*ptr2=&var2;
    rer(&ptr1,&ptr2);
    printf("%d %d",var2,var1);
}
  1. $60,70$
  2. $50,50$
  3. $50,60$
  4. $60,50$
retagged by

1 Answer

Best answer
12 votes
12 votes
$\underline{\textbf{Answer:}\Rightarrow}\;\;{\textbf{(d)}}$

$\underline{\textbf{Explanation:}\Rightarrow}$

Let's assume the addresses in terms of $\mathrm{x100, x200,\dots}$

Now,

$\mathrm{var1} = \underset{\mathrm x100}{\bbox[lightblue,5px,border: 2px solid red]{5}}\;\;$, $\mathrm{var2} = \underset{\mathrm x200}{\bbox[lightblue,5px,border: 2px solid red]{10}}$

$\mathrm{ptr1} = \underset{\mathrm x300}{\bbox[lightblue,5px,border: 2px solid red]{\mathrm x100}}\;\;$, $\mathrm{ptr2} = \underset{\mathrm x400}{\bbox[lightblue,5px,border: 2px solid red]{\mathrm x200}}\;\;$

Now, on calling the function $\underline{\mathbf{rer(\&ptr1, \;\&ptr2)}}$

$\require{cancel}{\mathrm{ptr2} = \underset{\mathrm x500}{\bbox[lightblue,5px,border: 2px solid red]{\cancel{\mathrm x300}_{\mathrm x400}}}\;\;,\mathrm{ptr1} = \underset{\mathrm x600}{\bbox[lightblue,5px,border: 2px solid red]{\cancel{\mathrm x400}_{\mathrm x300}}}\;\;}$

$\mathrm{ptr1} = \underset{\mathrm x700}{\bbox[lightblue,5px,border: 2px solid red]{\mathrm x300}}$

Now,

$\mathrm{**ptr1 \color{red}{*}= ** ptr2}$ means it will assign the product of the values of double pointer $\mathbf{ptr2}$ and $\mathbf{ptr1}$ to the double pointer $\mathbf{ptr1}$

$\therefore \;\;\require{cancel} \mathrm{var1} = \underset{\mathrm x100}{\bbox[lightblue,5px,border: 2px solid red]{\cancel{5}_{50}}}\;\;$, $\mathrm{var2} = \underset{\mathrm x200}{\bbox[lightblue,5px,border: 2px solid red]{10}}$

$\therefore $ After executing statement $\mathbf{**ptr2 \;+= \; **ptr1}$ which can be again simplified as

$\mathrm{**ptr2 = **ptr2 + ** ptr1\; = \; 50 + 10 = \mathbf{60}}$

So, after executing the below statement, output will be:

$\color{magenta}{\textbf{printf("%d%d",var2,var1);}}$

$\mathbf{Output = 60, 50}$

$\therefore \mathbf{(d)}$ is the correct option.
selected by
Answer:

Related questions

12 votes
12 votes
2 answers
1
srestha asked Jan 12, 2020
5,759 views
What is output of the following ‘C’ code assuming it runs on a byte addressed little endian machine?#include<stdio.h int main() { int x; char *ptr; x=622,100,101; pri...
0 votes
0 votes
0 answers
2
Ray Tomlinson asked Jul 5, 2023
881 views
#includeint main(){ int x;char *ptr;x=622,100,101;printf("%d",(*(char *)&x)*(x%3));return 0; }In this question what is the meaning of “ *(char *)&x “ ? please ...
6 votes
6 votes
5 answers
4
Satbir asked Jan 13, 2020
3,827 views
What is the output of the code given below?# include<stdio.h int main() { char name[]="satellites"; int len; int size; len= strlen(name); size = sizeof(name); printf("%d"...