Tuesday, April 16, 2013

Concepts of Programming Languages Chapter 5


Concepts of Programming Languages Chapter 5

Name            : Erland
NIM              : 1601218035
Lecturer       : Tri Djoko Wahjono, Ir., M.Sc. (D0206)
Assignment  : Concept of programming languages Chapter 5

Review Questions


       1.  what are the design issues for names?
             Answer : - Are names case sensitive ? 
                             Are the special words of the language reserved 
                                words or keywords ?

       2. What is the potential danger of case-sensitive name?
            Answer : Because case-sensitive violates the design principle that language
                            constructs that look similar should have similar meanings.

       3. In what way are reserved words better than keywords?
             Answer : As a language design choice, reserved words are better than
                             keywords because the ability to redefine keywords can be confusing.

       4. what is alias?
             Answer : Alias is more than variable with the same name that
                             can be used to access the same memory location.

       5. Which category of C++ reference variables is always aliases?
             Answer : One common way in C and C++ is with their union types.

        6. What is the l-value of a variable? What is the r-value?
             Answer:The address of a variable is sometimes called l-value, and 
                            a variable's value is sometimes called r-value.

        7.  Define binding and binding time.
               Answer : - Binding is an association between an attribute and an entity,
                                  such as between a variable and its type or value, or between
                                  an operation and a symbol.
                               - The time at which a binding takes place is called binding time.

        9. Define static binding and dynamic binding?
             Answer : Static binding is done at compile time when a function is
                             called in order to match it with the definition, while 
                             Dynamic binding is at run time where we can specify 
                              that the compiler matches a function call with the correct 
                              function definition at run time.

Problem Sets


1. Decide which of the following identifier names is valid in c language, support 
    your decision.
     Answer: - _student    : valid, because in C name can be started with an underline.
                    - int                : invalid, because int is a reserved data type for integer.
                    - Student       : valid, because in C uppercase is allowed.
                    - 123Student : invalid, because in C names can't be started with number.
                    - Student123 : valid, as long as the names not started with number it 
                                              is allowed.
                            
2. What is the l-value? write a statement in C language which gives the compile 
     error "l-value required".
     Answer: l-value is the address of a variable.
                     ex: printf("%d\n",*num++);

4.  Why is the type declaration of a variable necessary? What is the value range 
     of the int type variable in Java?
      Answer : Because the program have to know what data type of a variable and 
                      the value of the variable. The value range of the int type variable in 
                     Java is around -2147483648 to 2147483647.