edited by
1,272 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

13 13 votes
1 1 answer
1.1k
1.1k views
GO Classes asked Jul 2
1,141 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 ...
15 15 votes
2 2 answers
607
607 views
GO Classes asked Jul 2
607 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}$...
9 9 votes
1 1 answer
454
454 views
GO Classes asked Jul 2
454 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 ...
6 6 votes
1 1 answer
435
435 views
GO Classes asked Jul 2
435 views
What is printed by the following program?#include <stdio.h struct Student { int id, year; char grade; }; int main() { struct Student s; s.id = 10001; s.year = 2010; s.gra...