C void setValueunsigned int var unsigned int k unsigned int

C++

void setValue(unsigned int & var, unsigned int k, unsigned int i, unsigned int val);

This function takes in our storage variable by reference, the number of values k, the index of a value to set (0 through k - 1), and a value to set. You may assume that all inputs are valid. For example, assuming your unsigned int storage variable is x, in order to use the whole variable to store a value, you should be able to type something like setValue(x,1, 0, 1337). If you want to to be able to store 32 values (one value for each bit) and only assign the second bit to 1, then you should be able to type something like setValue(x, 32, 1, 1).

explain what the bold part means and how this parameter is being used

Solution

As per the question this function is to store value in a variable.

here the &var is the reference variable which takes actually makes a reference to the passed variable instead of just value.

Example : setValue(x,1,0,1337);

here the function takes the variable x as reference.

any changes made to \'var\' variable in setValue function makes changes to variable x also.

int main(){

/* code */

unsigned int x=0;

setValue(x,1,0,1337);

}

void setValue(unsigned int & var, unsigned int k, unsigned int i, unsigned int val){

/* code */

var=100;//just a example code

//above line makes a change to var this actually also change value x in main function because it is a referemce.

}

thus to set value to variable x we need to pass the reference to variable not just the value.

C++ void setValue(unsigned int & var, unsigned int k, unsigned int i, unsigned int val); This function takes in our storage variable by reference, the numbe

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site