A. Parameters: %u2026(8 points %uF0B7 If reference parameters can be used in any
ID: 3539837 • Letter: A
Question
A. Parameters: %u2026(8 points
%uF0B7 If reference parameters can be used in any function, why use value parameters
at all? %u2026(2 points)
%uF0B7 How are value parameters useful in processing data in a program? %u2026(2 points)
%uF0B7 Why is it generally not wise to combine value-returning functions with reference
parameters? %u2026(2 points)
%uF0B7 List 2 situations in which default parameters might be useful.. %u2026(2 points)
B. Arrays: %u2026(8 points Total)
%uF0B7 Wof bounds errors when reading into
C-strings? %u2026 (4 points).
%uF0B7 Discuss some useful applications for n-dimensional arrays, such as graphical 3-D
or biotechnology applications. %u2026(4 points)
Explanation / Answer
Reference Parameters: It always refers to the address of variable in main function and it modifies the main function variables in sub function. In case, the requirement is to not change any main function variables then the sub function will be coded to pass value parameter. It creates sperate copy of variables that means speperate memory location. This helps in not touching main program variables.
Value parameters: Value parameters always maintains seperate copy of data specific to sub program. It has its own memory location. It helps in calculaing and modifying the data inside sub program with out touching any main program variables. Once the subprogram execution get completed then the process returns back to main program and value parameters memory will be available to create new variables.
Value returning functions with reference: Usually, programer will opt value returning function in case if he wants to return only one parameter as result from sub function. In case, if the requirement is to modify and return multiple parameters then programmer will go for reference option. Though, it does not cause any harm of using both reference and value return type, but it may end up giving some kind of confusion later reading the same program. In other way, refering the original main function speads up the process as we are not creating any parameters inside the sub function.
Default parameters:
1. If the parameter is going to be same in most of the times, it is good to make it default as we dont need to pass multiple times and multiple places.
2. If multiple programs are using same function and each function does not require to pass all parameters then parameters that are option for some programs can be made default.
Arrays:
To prevent out of bound errors while reading strings:
1. One best way to mention the number of characters to be read from console based on C-string size. This never let the input string go beyond the size of the same.
2. One other way is to declare string variable as pointer than array. This helps in taking the maximum value rather restricting to the size of array that we usually mention while declaring variable.
Uses of n dimensional arrays:
I will describe simple example where we use n dimensional arrays most:
1. Student academic management system, if we want to maintain subject name on yearly basis for each student, we need to use multi dimensional arrays. Here, student ID are in one dimension, years are in one dimension and subject names for each year are in other dimension.
2. Vehicle management system, if we need to maintain yearly wise sales for each barnd of vehicle then we need to go for multi dimension arrays. Here, Vehicle is in one dimension, years are in one dimension and sales details are in one dimension. It can be drill down to another dimension called monthly wise sales
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.