|
-
Jan 5th, 2002, 11:47 AM
#1
Thread Starter
Hyperactive Member
what exactly ARE pointers
what exactly ARE pointers, and what are they for?
i knwo they can refer things to the address in the memory in which tey are stroed, &number, par example! but i dobnt understand... WHY! you would want to do that!, why not use a normal int/char etc?
Power to 2000 Electronic Donkeys!
www.edonkey2000.com
I hate case sensitivity... all you get down the M1 is "are we there yet" and "ouch, watch the bumps".
-
Jan 5th, 2002, 11:59 AM
#2
I am at Chapter 9 Sams book (Sams Teach yourself C++). I have just finished the chapter 8 who talk about Pointer.
Pointer is a ways to declare a variable to store is adress in the memory of the computer. With that you can take and change the value of that adress in all you function without declaring anything in public. I just know that it's very usefull but I do not understand all all I might read again that chapter later 
Hope that give you some information.
-
Jan 5th, 2002, 12:16 PM
#3
transcendental analytic
Pointers are lowlevel stuff
Pointers aren't meant to exist in a highlevel programming language but C++ is a hybrid. Main reason why there are pointers is because of backward compability with C.
Pointers are mainly useful for dynamical memory allocation, that is when you construct datastructures with variable size, such as arrays. Pointer aritmetics is a powerfull tool as well which often saves performance, dealing with C style strings you can skip a load of rutine that would waste performance of a string type, but on the other hand you would need to follow them strictly, a lot of bugs are related to lack of thinking lowlevel.
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Jan 6th, 2002, 09:51 AM
#4
Thread Starter
Hyperactive Member
yeh, but what good are they for, and what is the differance in using them and in usingint or osmething
Power to 2000 Electronic Donkeys!
www.edonkey2000.com
I hate case sensitivity... all you get down the M1 is "are we there yet" and "ouch, watch the bumps".
-
Jan 6th, 2002, 11:24 AM
#5
My guess is that you lack imagination, or you never run into a programming problem which could be solved using pointers.
Make more programs in C/C++ and you'll see by yourself the use of them. It's hard to explain what are they for as their use allow a lot of flexibility.
Personally they turn me on.
-
Jan 6th, 2002, 11:56 AM
#6
Thread Starter
Hyperactive Member
yeh, but i cant very welhem in a program if i dont know what to do with them can i!!!!!!!
give me a program ot do, and a use of pointers in that program, and hwy a normal int/char/float etc. wouldnt be as good.
I have heard the right use of pointers can make your program faster!!! but why!
this is what my book is seemingly failing to help me with here
Power to 2000 Electronic Donkeys!
www.edonkey2000.com
I hate case sensitivity... all you get down the M1 is "are we there yet" and "ouch, watch the bumps".
-
Jan 6th, 2002, 12:31 PM
#7
Monday Morning Lunatic
C example:
Code:
typedef struct _bigbugger {
int a, b, c, d, e, f, g;
double x, y, z;
} bigbugger;
void somecode(const bigbugger *ptr) {
printf("%d, %d, %d\n", ptr->a, ptr->b, ptr->c);
}
Here, this means that rather than copying the ENTIRE structure to the function, you pass a pointer instead - thus only 4 bytes are copied (for the pointer), rather than sizeof(bigbugger) bytes.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Jan 6th, 2002, 01:12 PM
#8
Here's your program:
Write a function that takes an integer and CHANGES it to it's own square. So when I write...
Code:
int i = 4;
// call the function with i
// then output i:
cout << i;
...the output is 16. C++ references are not allowed (although you should use them when you're doing real things).
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Jan 6th, 2002, 02:04 PM
#9
transcendental analytic
Another one: write your own resizable array
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Jan 6th, 2002, 02:07 PM
#10
Thread Starter
Hyperactive Member
i wont include includes etc!!!
Code:
int main()
{
int i = 4;
int t;
t = i * i;
cout << i;
return 0;
}
is that what you mean?
Power to 2000 Electronic Donkeys!
www.edonkey2000.com
I hate case sensitivity... all you get down the M1 is "are we there yet" and "ouch, watch the bumps".
-
Jan 6th, 2002, 02:09 PM
#11
Thread Starter
Hyperactive Member
Originally posted by kedaman
Another one: write your own resizable array
you mean like make
char nanny[]={ted,bill}
into something constantly addable to?
Power to 2000 Electronic Donkeys!
www.edonkey2000.com
I hate case sensitivity... all you get down the M1 is "are we there yet" and "ouch, watch the bumps".
-
Jan 6th, 2002, 02:10 PM
#12
Monday Morning Lunatic
Where did includes come into it? 
Code:
void square_it(int *num) {
*num *= *num;
}
void somecode(void) {
int x = 5;
square_it(&x);
}
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Jan 6th, 2002, 02:27 PM
#13
Thread Starter
Hyperactive Member
so why did you need pointers in that, what would have happened without the pointers?
Power to 2000 Electronic Donkeys!
www.edonkey2000.com
I hate case sensitivity... all you get down the M1 is "are we there yet" and "ouch, watch the bumps".
-
Jan 6th, 2002, 02:30 PM
#14
transcendental analytic
Hmm, looks like you need to learn some functional programming, but I'd recommend you go learn OOP directly, there's a online tutorial TYSC++ which is quite good: http://newdata.box.sk/bx/c/
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Jan 6th, 2002, 02:44 PM
#15
Thread Starter
Hyperactive Member
ok im gonna read a bit about functions, maybe this will make pointers clearer to me!
Power to 2000 Electronic Donkeys!
www.edonkey2000.com
I hate case sensitivity... all you get down the M1 is "are we there yet" and "ouch, watch the bumps".
-
Jan 6th, 2002, 03:09 PM
#16
Monday Morning Lunatic
Originally posted by JafferAB
so why did you need pointers in that, what would have happened without the pointers?
If I hadn't used a pointer, it would have modified the COPY that was sent to the function.
C and C++ pass by value (ByVal) as the default - VB uses ByRef.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Jan 6th, 2002, 03:46 PM
#17
No, I want you to write a function that basically does this:
i *= i; // will make i the square of itself
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Jan 6th, 2002, 03:46 PM
#18
Thread Starter
Hyperactive Member
ooooh, i see, i see why tht would be usefull because its very complex without that, you got a huge line thing in this here book and a massive program!
its just a matter of knowing when to use em!
Power to 2000 Electronic Donkeys!
www.edonkey2000.com
I hate case sensitivity... all you get down the M1 is "are we there yet" and "ouch, watch the bumps".
-
Jan 6th, 2002, 03:47 PM
#19
transcendental analytic
unfortunately parksie screwed it up
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Jan 6th, 2002, 03:48 PM
#20
Monday Morning Lunatic
Originally posted by kedaman
unfortunately parksie screwed it up
Why change the habit of a lifetime?
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Jan 6th, 2002, 04:39 PM
#21
transcendental analytic
Originally posted by parksie
Why change the habit of a lifetime?
yeah why? life is unfortunately
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Jan 7th, 2002, 12:37 PM
#22
Why you use pointers is the same reason why you pass a parameter ByRef in VB - so that:
a: you don't have to pass a mess of data on the stack, just one long. This is one big reason why it's faster.
b: so that when you alter the parameter, the change is reflected in the calling module as well.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|