Re: [Dev-C++] What's the difference?
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: <or...@vp...> - 2003-03-03 22:16:25
|
Hello!
> what's the difference between using pointers and using simple variables? How
> does this difference affects the performance of my code? I know that using
> pointers is working with memory addresses but using simple variables would
> not have the same effect?
It is advisable to use pointers when you use structures, because it is
faster and more convenient. Suppose you have this structure:
struct foo{
char *Text1;
char *Text2;
char *Text3;
};
If you have a function that has this structure as its argument, then it
is better to pass only a pointer to it (&foo_struct), beacuse it already
has pointers in it to character arrays, so you have the same result if
you pass pointer or pass the whole struct. But when passing the whole
struct, it will be copied, but the Texts won't, just the pointers to it.
So it is better to pass only pointers to structs, always. It will make
your code cleaner, and you can always assure yourself, that you always
declared functions to use pointers.
--
Greetings,
Balázs
|