Is someone looking to increase the speed of a program, or are they trying to 
save memory?
Forgive me if my observation is incorrect, as I am a new programmer myself.
 
As I think of it, when you pass a variable by value to a function, you are 
having to make another copy of the value thus taking up more space in memory 
for the duration of the function. Of course with how much RAM is in the average 
system now days this shouldn't too much of an issue. Passing by value is fine 
if you are only having to effect one value by a 'return' statement. 
 
But when your function changes several variables, you need to use pointer 
notation to be able to return more than one value (which in reality you're not 
returning anything but adjusting the variable itself through dereferencing). Of 
course one definite benefit here is you are not taking up extra memory by 
making a copy of every variable that is sent to the function. This saves space 
in RAM, and keeps the program from spending any clock time to make the copy. 
 
Also, if you can effect several variables that need to have the same function 
called upon them you can save yourself some personal time by not having to type 
more code. So...try to go for 'portability' when writing your programs.
 
As my teacher's advice was..."If only effecting one variable, pass by 
value...if effecting two or more variables pass by reference".
 
Please feel free to correct my thinking here because I would much rather learn 
to do it right <Smile>.
 
Michael

sheikh ishtiyaq <[EMAIL PROTECTED]> wrote:

Hi 
I dont think that using pointers can be faster than
using local variables. 
In some case,s it might be equal but can never be
faster. 
In case of accessing the memory for pointer needs to
access the data on the heap and there is one
indirection also involved. 
Bit on case of normal variables they are accessed
using direct stack memory.

Please give your comments.

Thanks 
Ishtiyaq


--- Darryl Sumner <[EMAIL PROTECTED]> wrote:

> 
> Hi,
> Pointers are in a lot of cases faster to use than
> variables. As stated in a previous post, type *name
> declares a pointer, pointers can only point to the
> type declared unless cast to another type. Be
> careful
> with casting though. Their are two other unary
> operators for pointers, the & and the *. The & is
> the
> "address of operator". Ex: p=&variable name;
> The other operator is *, "at address". Ex: cout <<
> *p
> << endl; This will print what the value of the
> variable pointer to is.
> 
> Ex: int *p,value=100;
>     p=&value;
>     printf("%d",*p) //prints 100
>     printf(p) //will print the address not 100
> 
> This also just scratches the surface though. I like
> books by Herb Schildt, he's easy to understand and
> detailed.
> Hope this helps,
> Darryl 
> 
> 
>             
> __________________________________ 
> Do you Yahoo!? 
> Dress up your holiday email, Hollywood style. Learn
> more. 
> http://celebrity.mail.yahoo.com
> 
> 
> 
> 



            
__________________________________ 
Do you Yahoo!? 
Yahoo! Mail - Find what you need with new enhanced search.
http://info.mail.yahoo.com/mail_250





>-----------------------------------------~-~>
CHECK THE ARCHIVE BEFORE POSTING!!!! Archive is available at 
http://www.eScribe.com/software/C-Paradise/

>------------------------------------------_->






---------------------------------
Yahoo! Groups Links

   To visit your group on the web, go to:
http://groups.yahoo.com/group/C-Paradise/
  
   To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
  
   Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service. 


                
---------------------------------
Do you Yahoo!?
 The all-new My Yahoo! � Get yours free!    

[Non-text portions of this message have been removed]



>-----------------------------------------~-~>
CHECK THE ARCHIVE BEFORE POSTING!!!! Archive is available at 
http://www.eScribe.com/software/C-Paradise/

>------------------------------------------_->


 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/C-Paradise/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 



Reply via email to