What happens to a parameter when it is input and called in a

What happens to a parameter when it is input and called in a function? What happens to a parameter when a function has executed and returns to main function? True or false? A function can only have one parameter as input to the function? Name one advantage of using arrays over vectors?

Solution

Ans)

q7) What happens to the parameter when it is input and called in a function?
Ans) The parameter is initialized and declared in a main function. But when this parameter is called in a function the value of the parameter is passed to that function. The function have the full scope to use that parameter and the will be executed.
Ex:
               using namespace std;
               int add(int, int);// Function prototype (declaration)

                   int main()
                   {
                       int num1, num2, sum;
                       cout<<\"Enters two numbers to add: \";
                       cin >> num1 >> num2;
                       -----------
                       -----------
                       -----------
                   }
                   // Function definition
                   int add(int a, int b)
                   {
                       int add;
                       add = a + b;
                       return add;// Return statement
                   }
           here num1 and num2 are parameters in main class and passed to the add funtion and perform the validations
          
Q8) What happens to the parameter when a function has executed and returns to main function?
Ans) When a parameter is passed to the function after execution the value is returned from the function to the main function.The parameter value remains unchanged but the executed result value is came to the main function and printed.
Ex:
                   // Function definition
                   int add(int a, int b)
                   {
                       int add;
                       add = a + b;
                       return add;// Return statement
                   }
                  
                   Here the parameters a and b are unchanged but the executed value add is returned to the main function.
                  
Q9)A function can only have one parameter as input to the function?True or false
Ans)False
       Because the function have one or more parameters as a input value.The above example have two input parameters.
  
  
Q) Name one advantage of using arrays over vectors?
Ans)   Arrays have more efficiency compared to vectors.Coming to the behavioural control arrays are more useful compared to vectors.If we want to initialize the size statically then arrays are more useful.Arrays are faster compared to vectors.

 What happens to a parameter when it is input and called in a function? What happens to a parameter when a function has executed and returns to main function? T

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site