| Author | 
		Message | 
	
		 
		Junaid2pac
 
 
 
    
		 | 
		
		
			
				  Posted: Sat Apr 21, 2007 5:34 pm    Post subject: pointer question  | 
	
				
				 | 
			 
			 
				
  | 
			 
			
				This code was at cplusplus.com
 
 
// more pointers
 
#include <iostream>
 
using namespace std;
 
 
int main ()
 
{
 
  int firstvalue = 5, secondvalue = 15;
 
  int * p1, * p2;
 
 
  p1 = &firstvalue;  // p1 = address of firstvalue
 
  p2 = &secondvalue; // p2 = address of secondvalue
 
  *p1 = 10;          // value pointed by p1 = 10
 
  *p2 = *p1;         // value pointed by p2 = value pointed by p1
 
  p1 = p2;           // p1 = p2 (value of pointer is copied)
 
  *p1 = 20;          // value pointed by p1 = 20
 
  
 
  cout << "firstvalue is " << firstvalue << endl;
 
  cout << "secondvalue is " << secondvalue << endl;
 
  return 0;
 
}
 
 
 
 
My Question
 
If *p1 = 20 then why does firstvalue = 10[/list] | 
			 
			
				 | 
			 
		  | 
	
	 
		 | 
		
		 | 
	
	
 
		  | 
	
		 
		Sponsor Sponsor 
		 
  
		 | 
		
 | 
	
	 
		  | 
	
				 
		Junaid2pac
 
 
 
    
		 | 
		
		
			
				  Posted: Sat Apr 21, 2007 5:40 pm    Post subject: Re: pointer question  | 
	
				
				 | 
			 
			 
				
  | 
			 
			
				| sorry nvm | 
			 
			
				 | 
			 
		  | 
	
	 
		 | 
		
		 | 
	
	
 
		  | 
	
				 
		Junaid2pac
 
 
 
    
		 | 
		
		
			
				  Posted: Sat Apr 21, 2007 11:11 pm    Post subject: Re: pointer question  | 
	
				
				 | 
			 
			 
				
  | 
			 
			
				| But can someone explain to me how pointers can be used in functions | 
			 
			
				 | 
			 
		  | 
	
	 
		 | 
		
		 | 
	
	
 
		  | 
	
				 
		wtd
 
 
 
    
		 | 
		
		
			
				  Posted: Sun Apr 22, 2007 12:21 am    Post subject: RE:pointer question  | 
	
				
				 | 
			 
			 
				
  | 
			 
			
				| Understand how pointers work, how scope works, and how function parameters work.  If you understand these things, your questions about pointers and functions will be answered. | 
			 
			
				 | 
			 
		  | 
	
	 
		 | 
		
		 | 
	
	
 
		  | 
	
				 
		Junaid2pac
 
 
 
    
		 | 
		
		
			
				  Posted: Tue Apr 24, 2007 8:11 pm    Post subject: Re: pointer question  | 
	
				
				 | 
			 
			 
				
  | 
			 
			
				I understand how functions work but i thought i saw something saying that u can't input arrays into a function, instead u have to use pointer instead
 
 
Is that true? | 
			 
			
				 | 
			 
		  | 
	
	 
		 | 
		
		 | 
	
	
 
		  | 
	
				 
		wtd
 
 
 
    
		 | 
		
		
			
				  Posted: Wed Apr 25, 2007 1:05 am    Post subject: RE:pointer question  | 
	
				
				 | 
			 
			 
				
  | 
			 
			
				| False dichotomy. | 
			 
			
				 | 
			 
		  | 
	
	 
		 | 
		
		 | 
	
	
 
		  | 
	
				 
		 |