In: Computer Science
The Questions Are of a Organization of Programming course.
A variable can be characterized by a collection of attributes. What is one such attribute? The response is Implicit heap-dynamic allocation. Why is the response that?
Does static type binding require the programmer to specify the type of the variable in the program? Please Explain the answer and why it is the answer.
A certain variable is assigned a value. At that time, new storage is allocated for that variable to fit the new value. What kind of allocation was most likely used? Please provide an answer and please explain why the answer is the answer.
Variables generally have four attributes: an identifier, data location, type and value. They are assigned during program execution at different times.An identifier is a string of alphanumeric characters that begins with an alphabetic character or an underscore character that are used to represent various programming elements such as variables, functions etc.Data location shows the location of data stored.variable types specify the kind of information stored in a variable and value denotes what the variable holds.
A binding is static if binding of attributes to variables first occurs before run time and remains unchanged throughout the program execution.If static, the type may be specified by either an explicit or an implicit declaration.
An explicit declaration is a program statement used for declaring the types of variables.it lists variable names and specifies their types.for eg- var x: int
An implicit declaration is a default mechanism for specifying types of variables (the first appearance of the variable in the program).for eg:x=3.Here value of x is int and will not change afterwards.
If it becomes necessary to generate variable with new value,we can use pointers and dynamic memory. Dynamically allocated variables live in a piece of memory known as the heap, these are requested by the running program using the keyword "new".This memory does not come from the program’s limited stack memory -- instead, it is allocated from a much larger pool of memory managed by the operating system(heap) .In modern machines, the heap can be gigabytes in size. A dynamic variable can be a single variable or an array of values, each one is kept track of using a pointer. After a dynamic variable is no longer needed it is important to deallocate the memory, return its control to the operating system, by calling "delete" on the pointer.