Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 pointer question
Index -> Programming, C++ -> C++ Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Junaid2pac




PostPosted: 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
Sponsor
sponsor
Junaid2pac




PostPosted: Sat Apr 21, 2007 5:40 pm   Post subject: Re: pointer question

sorry nvm
Junaid2pac




PostPosted: 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




PostPosted: 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




PostPosted: 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




PostPosted: Wed Apr 25, 2007 1:05 am   Post subject: RE:pointer question

False dichotomy.
Display posts from previous:   
   Index -> Programming, C++ -> C++ Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 6 Posts ]
Jump to:   


Style:  
Search: