Post Reply 
Local variables - C Style
11-07-2015, 01:41 PM (This post was last modified: 11-07-2015 01:45 PM by peacecalc.)
Post: #4
RE: Local variables - C Style
Hello alen12345,

I don't understand c++, but the scope of local variables are easy with the hp 50g.

You have three places where you can store values of any kind.

a) stack
b) global variables
c) local variables

Every main program is enclosed between "<<" ">>" . If a nested pair of "<<" ">>" exist, it is the opertunity to create a local variables, have a short look:

Code:

<<  2. 3.  -> A B          @@create and load local A with 2. and B with 3.
       <<                  @@between this brackets the locals A and B exist
            5. 'A' STO     @@overwrite contents of A with 5.
            A B            @@put value of A on stack 2 and value of B on stack 1
       >>                  @@between this brackets the locals A and B exist 
A                          @@outside the scope, the program returns only 'A'
                           @@as an variable name (as an algebraic term), with no physical
                           @@store place 
>>

The recalling above involved the stack of course, but normally you will do something with the value, for example to feed another function, so the stack becomes empty like before.

Maybe interesting for you: if you use locals in a loop and you interrupt with HALT, you can load the local variables with new values (with STO) or you can recall their values (with RCL), but you must have the local variable names in mind (good for debugging) because these names doesn't appear if you press VAR on your calc.

greetings
peacecalc
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Local variables - C Style - alen12345 - 11-07-2015, 09:08 AM
RE: Local variables - C Style - Han - 11-07-2015, 12:28 PM
RE: Local variables - C Style - alen12345 - 11-07-2015, 12:48 PM
RE: Local variables - C Style - peacecalc - 11-07-2015 01:41 PM
RE: Local variables - C Style - C.Ret - 11-08-2015, 02:52 PM
RE: Local variables - C Style - peacecalc - 11-08-2015, 07:28 PM



User(s) browsing this thread: 1 Guest(s)