• edited by
1,286 views
1 1 vote
consider the foloowing program: 
int main()
{
  int var1=35, *var2,*var3;
  var2=&var1;//suppose address of var1 1006
  var3=var2;
  *var2++=*var3++;
  var1++;
  printf("var1=%d var2=%d var3=%d",var1,var2,var3);
  return0;
}

output print by above program ?

1 Answer

Best answer
2 2 votes
  1. int main()
  2. {
  3. int var1=35, *var2,*var3;
  4. var2=&var1;    //means var2 also ponts to var1
  5. var3=var2;     // means var3 also point to var1
  6. *var2++=*var3++;   //means value at var2 address will be replced by value at var3 address which is same i.e. 35 no change,  after that var2 and var3 adress is incermented means point to location which contain garbage i.e. 1010 , 1010
  7. var1++;   // var1 value increament by 1 = var1= 36
  8. printf("var1=%d var2=%d var3=%d",var1,var2,var3);  // 36 , 1010 ,1010 
  9. since i aasume pointer take 4 Byte so 1006 +4 = 1010
  10. return0;
  11. }
• selected by
Position:
Show:

Related questions

1 1 vote
1 1 answer
307
307 views
khanshahima4 asked Sep 24
307 views
1. If precedence tells me which operator has priority, and associativity tells me how to handle operators at the same level, then why do I need a separate concept called ...
14 14 votes
1 1 answer
1.4k
1.4k views
GO Classes asked Jul 2
1,376 views
Assume:$\texttt{short = 2 bytes}$, $\texttt{int = 4 bytes}$, $\texttt{char = 1 byte}$$\texttt{int}$ needs $4$-byte alignment and the final structure size is rounded to a ...
18 18 votes
2 2 answers
767
767 views
GO Classes asked Jul 2
767 views
Assume:struct Student { double gpa; }; struct Student alice; struct Student *sptr = &alice;Which of the following correctly assigns $\texttt{4.0}$ to $\texttt{alice.gpa}$...
10 10 votes
1 1 answer
570
570 views
GO Classes asked Jul 2
570 views
Consider the following code idea from the source:typedef struct { double x, y; } Point; void reset(Point p) { p.x = p.y = 0; } int main() { Point a = {12.0, 42.0}; Point ...