Symbol table and memory allocation (functions and variables) :
There is a single stack that allocates memory for all the variables (global + local), unlike C, where each function has a local stack for local variables and a standard data segment for global and static variables
For every local variable memory is allocated from stack, but it also gets an entry in the local symbol table, thus differentiating it from any global variable of same name.
The local variables of a function are allocated memory dynamically during run time.
This local symbol table is destroyed while returning form the function, hence memory is released from stack.
However the memory allocated to the argument variables in the function definition stays.
For a function (defined by "def"), the arguments defined are not unallocated unless we explicitly mention "undef", hence memory wastage is more.
Symbol table is a data structure associated with the function, but the stack is the data structure associated with the program.
We can define a function, where arguments have a keyword associated to them
so in case of function calling we may randomize the order of actual parameters, while attaching them to there specific keywords as in formal parameters.
eg.
def func(a, b, c, d): print "a = {} b = {} c = {} d = {}".format(a, b, c, d)
func(a = 10, c = 20, b = 30, d = 40)
will print -->> a = 10 b = 30 c = 20 d = 40
We may even use "*custom" (any name will do, not a keyword) in case of formal arguments, when we dont know the exact number of actual parameters in the function call statement
eg.
*custom
def func(*custom): for arg in custom : print "Next argument : ", arg func('lets', 'have', 'fun', 55, [1, 2, 3])
will print --->>
Next argument : lets Next argument : have Next argument : fun Next argument : 55 Next argument : [1, 2, 3]
Today i am started work in python. I do some assignments program.Which are given by sir.Python is a very simple language and very easy for doing work. I made a program of find lcm of two number and also write a program on the greatest divisible number (gdc) of two number. I am also work on c, in c i am made a program.Inwhich is read a text file and replaced a specific character by the other character in the text file.