![]() |
| | #16 |
| Kiss the monkey. Join Date: Sep 2001
Posts: 810
| *i becomes 4, but k remains 3*
__________________ "If you tell the truth, you don't have to remember anything" -Mark Twain |
| CodeMonkey is offline | |
| | #17 |
| C++ noob Join Date: Jan 2009
Posts: 43
| Ok so when using i++, the int k will become what i was but then i will change and the k will not change because the post-increment makes it so that only the i changes. But the pre-increment makes the i change before the int k makes itself equal to i so they would both be the same.(Does that make sense?) PS: This is completely unrelated to anything we were talking about but i was just wondering, how do you get a signature? |
| Ryan0773 is offline | |
| | #18 |
| Kiss the monkey. Join Date: Sep 2001
Posts: 810
| That's one way to think about it. Think about it more literally and it might be simpler. ++i adds one to i and returns i i++ returns a temporary copy of i and then adds one to the real i. *edit* "user cp" for the signature.
__________________ "If you tell the truth, you don't have to remember anything" -Mark Twain Last edited by CodeMonkey; 01-04-2009 at 02:09 AM. |
| CodeMonkey is offline | |
| | #19 |
| C++ noob Join Date: Jan 2009
Posts: 43
| Thanks alot! |
| Ryan0773 is offline | |
| | #20 |
| C++ noob Join Date: Jan 2009
Posts: 43
| I still dont completely understand how to use pointers. I barely understand what their actual purpose is. Apparently they help to make sure that you have enough space for your program and that you arent wasting any space either. Please help, the whole purpose of pointers just isnt clear. How are they supposed to help your program? when should you use them? HOW do you use them? They just dont seem to make any sense. |
| Ryan0773 is offline | |
| | #21 | ||
| C++ Witch Join Date: Oct 2003 Location: Singapore
Posts: 10,352
| Quote:
Quote:
Another use would be to manage a dynamically allocated array, or to create links between the nodes of a linked list. However, this use is largely replaced by containers that abstract away the use of pointers.
__________________ C + C++ Compiler: MinGW port of GCC Build + Version Control System: SCons + Bazaar Look up a C/C++ Reference and learn How To Ask Questions The Smart Way | ||
| laserlight is offline | |
| | #22 |
| C++ noob Join Date: Jan 2009
Posts: 43
| Yes, i did read the tutorial. I can sortof make a basic pointer that points to another integer. but whats the purpose of codes like Code: int *pnt = new int; Code: delete ptr; The second one is supposed to delete a pointer that was allocated with new. Thats doesn't really help me if I dont understand the purpose of new. |
| Ryan0773 is offline | |
| | #23 | ||
| C++ Witch Join Date: Oct 2003 Location: Singapore
Posts: 10,352
| Quote:
Quote:
__________________ C + C++ Compiler: MinGW port of GCC Build + Version Control System: SCons + Bazaar Look up a C/C++ Reference and learn How To Ask Questions The Smart Way | ||
| laserlight is offline | |
| | #24 | |
| C++ noob Join Date: Jan 2009
Posts: 43
| Quote:
So this makes the ptr a null pointer? | |
| Ryan0773 is offline | |
| | #25 | ||
| C++ Witch Join Date: Oct 2003 Location: Singapore
Posts: 10,352
| Quote:
Quote:
Code: ptr = 0; Code: ptr = NULL;
__________________ C + C++ Compiler: MinGW port of GCC Build + Version Control System: SCons + Bazaar Look up a C/C++ Reference and learn How To Ask Questions The Smart Way | ||
| laserlight is offline | |
| | #26 | |
| C++ noob Join Date: Jan 2009
Posts: 43
| Like when you write a code that has an int with a certain interger assigned to it Code: int x(10); Quote:
| |
| Ryan0773 is offline | |
| | #27 | ||
| C++ Witch Join Date: Oct 2003 Location: Singapore
Posts: 10,352
| Quote:
Code: int* ptr = new int(10); Code: *ptr = 10; Quote:
__________________ C + C++ Compiler: MinGW port of GCC Build + Version Control System: SCons + Bazaar Look up a C/C++ Reference and learn How To Ask Questions The Smart Way | ||
| laserlight is offline | |
| | #28 |
| C++ noob Join Date: Jan 2009
Posts: 43
| I'm not sure that it was. Alright ill check it out,thanks. But does is there a way that i can change the characteristics of a certain pointer like *p which point to int i, could i change it so that later in the script *p would go from i to x? |
| Ryan0773 is offline | |
| | #29 | |
| C++ Witch Join Date: Oct 2003 Location: Singapore
Posts: 10,352
| Quote:
__________________ C + C++ Compiler: MinGW port of GCC Build + Version Control System: SCons + Bazaar Look up a C/C++ Reference and learn How To Ask Questions The Smart Way | |
| laserlight is offline | |
| | #30 |
| C++ noob Join Date: Jan 2009
Posts: 43
| How would i write that in code would it be something like... Code: {
int i;
int x;
int *p
p = &i
cout<< *p <<"\n";
int *p = new int(x);
cout<< *p <<"\n";
delete p;
*p = 0;
cin.get();
}
|
| Ryan0773 is offline | |
![]() |
| Tags |
| basic, basics, c++, lots, noob |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Several Questions, main one is about protected memory | Tron 9000 | C Programming | 3 | 06-02-2005 07:42 AM |
| Trivial questions - what to do? | Aerie | A Brief History of Cprogramming.com | 23 | 12-26-2004 09:44 AM |
| Questions. | anonytmouse | A Brief History of Cprogramming.com | 4 | 05-19-2004 02:16 PM |
| C++ test questions | Mister C | C++ Programming | 9 | 09-08-2002 12:05 PM |