Question

(1) Discuss the rules involving actual parameter lists, including matching data types and a one-to-one correspondence...

(1) Discuss the rules involving actual parameter lists, including matching data types and a one-to-one correspondence with the formal parameter list. Note that the parameter list can be empty, but the function call will still require parentheses after the function name.

(2) Discuss scope rules with respect to global and local identifiers, nested blocks, and functions.

(3) Discuss how local declarations are stored in computer memory. Are there any reasons to avoid using local declarations if it is possible to achieve the same result without them?

c++ programming language.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

QUESTION 1: - DISCUSS THE RULES INVOLVING ACTUAL PARAMETER LIST.

  • THE SYNTAX TO PASS ACTUAL PARAMETER LISTS IS:

Function name (Parameter1, Parametert2, …)

WHERE,

               Function name: - is the name of the function to be called.

               Parameters: - we can pass Parameters as many as needed, these are the actual values

            on which the function will operate.

  • THE DATA TYPE OF ACTUAL PARAMETER SHOULD BE SAME AS THE DATA TYPE OF FORMAL PARAMETER DECLARED CORRESPONDING TO IT IN FUNCTION DEFINITION.

SUPPOSE IF THE DATA TYPE OF THE ACTUAL PARAMETER, AND FORMAL PARAMETER IS DIFFERENT, THEN THE COMPILER WILL SHOW ERROR AS WRONG DATA TYPE CONVERSION FROM ACTUAL PARAMETER TO FORMAL PARAMETER.

  • THE NUMBER OF ACTUAL PARAMETERS PASSED IN FUNCTION CALL SHOULD BE EQUAL TO THE NUMBER OF FORMAL PARAMETERS DECLARED IN FUNCTION DEFINITION, i.e.: - THERE MUST EXIST ONE TO ONE CORRESPONDENCE BETWEEN ACTUAL AND FORMAL PARAMETERS.

WITH ONE TO ONE CORRESPONDENCE BETWEEN ACTUAL AND FORMAL PARAMETERS, IT’S VERY EASY FOR THE COMPILER TO DECIDE WHICH VALUE IS PASSING TO WHICH FORMAL PARAMETER.

Note that the parameter list can be empty, but the function call will still require parentheses after the function name:

  • THE PARENTHESIS IS REQUIRED IN A FUNCTION CALL EVEN WHEN THERE IS NO PARAMETER IS PASSED BECAUSE TO DEFINE IT AS A FUNCTION AND NOT AS A VARIABLE.
  • THE FUNCTION CALL WITH NO ARGUMENTS IS CALLED AS DEFAULT CONSTRUCTOR.
  • IF WE DON’T USE PARENTHESIS AFTER THE FUNCTION CALL THEN THE COMPILER WILL SHOW ERROR.

QUESTION 2: - Discuss scope rules with respect to global and local identifiers, nested blocks, and functions.

  • THE SCOPE RULES DECIDES IN WHICH PART OF THE PROGRAM A PARTICULAR PIECE OF CODE OR A DATA ITEM CAN BE ACCESSED.
  • THE LOCAL IDENTIFIERS CAN NOT BE ACCESSED OR USED OUTSIDE THE BLOCK IN WHICH THEY ARE DECLARED.
  • GLOBAL IDENTIFIERS CAN BE ACCESSED FROM ANY PART OF THE PROGRAM.
  • GLOBAL IDENTIFIERS ARE DECLARED AT THE TOP OF THE PROGRAM OUTSIDE ALL OF THE FUNCTIONS AND BLOCKS BUT CAN BE ACCESSED BY THEM.
  • IDENTIFIERS DECLARED IN THE FUNCTION HAVE FUNCTION SCOPE. THEY CAN BE ACCESSED ONLY IN THE FUNCTION THAT DECLARES THEM.
  • IDENTIFIERS DECLARED WITHIN A BLOCK HAVE BLOCK SCOPE AND ARE VISIBLE FROM THEIR POINTS OF DEFINITION TO THE END OF THE BLOCK.

QUESTION 3: - Discuss how local declarations are stored in computer memory.

  • THE PROGRAM MAKES THE SPACE FOR THE STORAGE OF DATA.
  • WHEN A VARIABLE OF A DATA IS DECLARED ENOUGH MEMORY IS ALLOCATED LOCALLY TO STORE THE DATA OF THAT TYPE.
  • HERE ARE THE MEMORY REQUIREMENTS OF DATA TYPES: -
    • int: integer number takes 4-bytes of space
    • short: integer number takes 2-bytes of space
    • long: integer number takes 8-bytes of space
    • char: character takes 1-byte of space
    • float: floating-point number takes 4-bytes of space and precision up to 6 digits
    • double: floating-point number takes 8-bytes of space
  • SUPPOSE WE HAVE: -

int a = 5;

THEN THE COMPILER CREATES A MEMORY SPACE OF ”4” BYTES OF SPACE AND NAME THAT   LOCATION AS “a” AND STORE THE VALUE “5” IN IT.

Are there any reasons to avoid using local declarations if it is possible to achieve the same result without them?

  • NO, BECAUSE WITH LOCAL DECLARATIONS WE CAN: -
  • EASILY CHECK FOR ERRORS WHILE DEBUGGING.
  • EASILY CHANGE OR MODIFY THE VALUE OF LOCAL DECLARATIONS.
  • EASILY INSPECT, WATCH OR PRINT THE VALUE OF LOCAL DECLARATIONS.
  • MAKES CODES CLEARER TO USE ONE TIME USED VARIABLES.
  • BREAK CHAINS OF METHOD CALLS.
Add a comment
Know the answer?
Add Answer to:
(1) Discuss the rules involving actual parameter lists, including matching data types and a one-to-one correspondence...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT