Question

In: Computer Science

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?

Solutions

Expert Solution

1). ANSWER :

GIVENTHAT :

TO 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.

2).TO 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.

3).TODiscuss 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.

Related Solutions

(a) Discuss how an actual parameter is related to its corresponding formal parameter in the following...
(a) Discuss how an actual parameter is related to its corresponding formal parameter in the following four parameter-passing methods for procedure calls. a. Pass by value b. Pass by reference c. Pass by name (b) Given the output of the following program (written in C syntax) using the above three parameter-passing methods: int i, j, a[5]; // a is a 5 element array with indices 0 - 4 void swap(int x, int y) { int temp = x; x =...
The best quote is one which the exporter lists different pricesfor different Incoterms rules, allowing...
The best quote is one which the exporter lists different prices for different Incoterms rules, allowing the importer to choose the best option for his specific case. a. TRUE. b. FALSE.Special English is used for written communications, just as International English is practiced. a. TRUE. b. FALSE.
One of the approaches the ATO uses to ensure compliance is data matching. What is it...
One of the approaches the ATO uses to ensure compliance is data matching. What is it and how does maintaining records assist the taxpayer in complying with the requirements of the ATO? 80–120 words In contect of Australia , Please do not copy paste from other source
Identify the four types of nonexchange transactions and discuss the rules for recognition of revenues and...
Identify the four types of nonexchange transactions and discuss the rules for recognition of revenues and expenses/expenditures for each type of transaction.
This data table lists the most common types of cancer in the United States, and includes...
This data table lists the most common types of cancer in the United States, and includes information on the known or likely carcinogens, estimated cases per year, and estimated deaths per year in 2014. Cancer in the United States (Ranked by number of cases) Cancer Known or Likely Carcinogenes or Factors Estimated cases (2014) Estimated deaths (2014) Breast Estrogen; possibly dietary fat 235,000 40,400 Prostate Testosterone; possibly dietary fat 233,000 29,500 Lung Cigarette smoke 224,000 159,000 Colon and rectum High...
Discuss each of the three (3) Rules of Risk Management. Select one (1) of the 4...
Discuss each of the three (3) Rules of Risk Management. Select one (1) of the 4 boxes of the frequency/severity matrix (p. 59 of fundamentals of risk and insurance, 11th edition) and identify a peril that fits into that box and how a risk manager might handle that risk.
Mergesort is known to be one of the fastest algorithms for sorting lists of data. In...
Mergesort is known to be one of the fastest algorithms for sorting lists of data. In fact, the runtime of mergesort is proportional to n· logn where n is the size of the list to be sorted. Bubblesort, on the other hand is a much slower algorithm, since it's runtime is proportional to n2 , where n is the size of the list to be sorted. As an experiment, mergesort is run on a slow computer, bubblesort is run on...
Discuss different types of shock including pathophysiology, symptoms, and treatment?
Discuss different types of shock including pathophysiology, symptoms, and treatment?
give a current case involving one of the types of ‘Crimes in the Business World”  that pertains...
give a current case involving one of the types of ‘Crimes in the Business World”  that pertains to Securities Fraud, Arson, Bribery, Forgery, Perjury, Embezzlement, Extortion or other Business Related Crimes please answer the question in a long paragraph
One of the approaches the IRC (Internal Revenue Commission) uses to ensure compliance is data matching....
One of the approaches the IRC (Internal Revenue Commission) uses to ensure compliance is data matching. What is it and how does maintaining records assist the taxpayer in complying with the requirements of the IRC? (80-120 words)
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT