in Compiler Design recategorized by
4,600 views
15 votes
15 votes

What are $x$ and $y$ in the following macro definition?

macro	Add x, y
        Load y
        Mul x
        Store y
end macro	
  1. Variables
  2. Identifiers
  3. Actual parameters
  4. Formal parameters
in Compiler Design recategorized by
4.6k views

3 Comments

  • formal parameter — the identifier used in a method to stand for the value that is passed into the method by a caller.
    • For example, amount is a formal parameter of processDeposit
  • actual parameter — the actual value that is passed into the method by a caller.
    • For example, the 200 used when processDeposit is called is an actual parameter.
    • actual parameters are often called arguments

An identifier is a name used for a class, a variable, a method, or a parameter

Source of informtion

6
6

If you are wondring what amount and processDeposit mentioned above is. Here is the code

class CheckingAccount
{
  . . . .
  private int balance;

  . . . .
  public void processDeposit( int amount )
  {
    balance = balance + amount ; 
  }

}
class CheckingAccountTester
{
  public static void main( String[] args )
  {
    CheckingAccount bobsAccount = new CheckingAccount( "999", "Bob", 100 );
    
    bobsAccount.processDeposit( 200 );

    . . . . . .
    
  }
}

Source: https://chortle.ccsu.edu/Java5/Notes/chap34A/ch34A_2.html

0
0
This type of question is in   syllabus 2022?
1
1

3 Answers

15 votes
15 votes

ans is D

  • formal parameter — the identifier used in a method to stand for the value that is passed into the method by a caller.
    • For example, amount is a formal parameter of calculate
  • actual parameter — the actual value that is passed into the method by a caller.
    • For example, the 800 used when calculate is called is an actual parameter.
    • actual parameters are often called arguments
float calculate (float amount)
{
 return amount * 1.2;   
}

int main()
{
  ...
  float final = calculate(800);
  ...
}
edited by

4 Comments

@junk_mayavi 

in macro definition these are formal but when replacement done in the actual code then it is actual parameters ,right?

0
0

@rahul it is formal  parameters from preprocessor point of view. after preprocessing, there won’t be any such distinction. pic is of section “C preprocessor “ from Dennis ritchie- C programming language. 

1
1
yes true. from macro it is formal parameters.I was thinking after the preprocessor but then it is no longer formal.Thanks:)
0
0
1 vote
1 vote

A parameter or argument is data which is taken as input or considered as additional information by the function for further processing. There are two types of parameters or arguments. The parameters which are passed in the function call are known as actual parameters or actual arguments. The parameters which are received by the called function are known as formal parameters or formal arguments. Example is shown below:

 

actuval-formal-params

In the above example, x and y are known as actual parameters and a and bare known as formal parameters.

0 votes
0 votes
macro Add x, y
    Load y
    Mul x
    Store y
end macro

In the given macro definition:  x and y are formal parameters of the macro.

Formal Parameters: These are placeholders or symbols used in the definition of a macro. They act as variables within the macro definition and are replaced by actual values or expressions when the macro is invoked. In the provided macro definition, x and y are formal parameters. When you use this macro, you would provide actual values for x and y as arguments, and the macro would substitute those values into the macro body.

For example, if you invoke the macro as follows:

Add a, b

It would be replaced as:

Load b
Mul a
Store b

 

Answer:

Related questions