GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  Concepts  >  OOPS
Go To First  |  Previous Question  |  Next Question 
 OOPS  |  Question 47 of 68    Print  
What is the difference between ++*p and (*p)++

  
Total Answers and Comments: 3 Last Update: November 15, 2007     Asked by: vijayn 
  
 Sponsored Links

 
 Best Rated Answer
Submitted by: harpreet sran
 
in ++*p firstly it will move to the incremented address of the pointing variable &from there the value will pick up the value of the variable, then it will assign to the corresponding variable or to itself.  In (*p)++ it will first assign value and then will increment its pointing position. 

Above answer was rated as good by the following members:
savya, rajani_vaddepalli15
September 13, 2007 04:43:34   #1  
sujatha        

RE: What is the difference between ++*p and (*p)++

int main ()
{
int firstvalue 5 secondvalue 15;
int * p1 * p2;

p1 &firstvalue;
p2 &secondvalue;

cout << "firstvalue is " << firstvalue << endl;
cout << "secondvalue is " << secondvalue << endl;

cout << "++*p1 is " << ++*p1 << endl;
cout << "(*p1)++ is " << (*p1)++ << endl;
return 0;
}


output:

firstvalue is 5
secondvalue is 15
++*p1 is 6
(*p1)++ is 6


 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    
October 26, 2007 08:08:56   #2  
Ramakrishna Reddy        

RE: What is the difference between ++*p and (*p)++
hi!

++*p means prefix of the variable.

Ex1:
class
{
int *p 4;
int *q ++*p;
s.o.p(*q);
}

output:
the value of *q is 5.

*p++ means postfix of the variable.
Ex2:

class
{
int *p 4;
int *q *p++;
s.o.p(*q);
}

output:
the value of *q is 4.

Ex3:

class
{
int i 5;
int j i++;
int k i++;
int t i;
s.o.p(t);
}

output:
the value of j is 5
the value of k is 6
the value of t is 7.


 
Is this answer useful? Yes | No
November 15, 2007 02:02:49   #3  
harpreet sran        

RE: What is the difference between ++*p and (*p)++
in ++*p firstly it will move to the incremented address of the pointing variable &from there the value will pick up the value of the variable then it will assign to the corresponding variable or to itself. In (*p)++ it will first assign value and then will increment its pointing position.
 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape