Answer each of the following:
- The _____ operator returns the location in memory where its operand is stored.
- The _____ operator returns the value of the object to which its operand points.
- To accomplish pass-by-reference when passing a nonarray variable to a function, it’s necessary to pass the _____ of the variable to the function.
(a)
To find the name of the operator that returns the memory location of an operand.
& operator.
Explanation of Solution
In C programming, language and symbol are used to get the address of an operand. The symbol (&) is also known as the ‘Address of’ operator.
Sample Program:
//include essential header files #include <stdio.h> //main function intmain() { //declare an operand int sample; //Print the address of operand named sample printf("%p",&sample); return0; }
Sample output:
(b)
To find the name of the operator that returns the value of an object who points to other operands.
* operator.
Explanation of Solution
In C programming language, * symbol is used to get the value of other operands that address it points.
Sample Program:
//include essential header files #include <stdio.h> //main function intmain() { //declare a operand int sample =10; //declare a pointer type operand int*point; point =&sample; //Print the value printf("%d",*point); return0; }
Sample output:
(c)
To find the component of a variable that should be passed to a function to accomplish pass by reference.
address.
Explanation of Solution
In pass by reference, any changes that a function performs on the passed variable always gets reflected in the actual variable. For this to accomplish, the address of the variable must be passed to function.
Sample Program:
//include essential header files #include <stdio.h> //function defination void passRef(int*a,int*b) { //declare a temp variable int temp; //assign variable a value to temp variable temp =*a; //assign variable b value to variable a *a =*b; //assign variable temp value to variable b *b = temp; //return the value return; } //main function intmain() { //declare variable int sample1 =10; int sample2 =15; //calling function using address of sample1 and sample2 passRef(&sample1,&sample2); //Print the values after swapping printf("sample1 = %d sample2 = %d", sample1, sample2); return0; }
Sample output:
Want to see more full solutions like this?
Chapter 7 Solutions
C How to Program (8th Edition)
Additional Engineering Textbook Solutions
Starting Out with Programming Logic and Design (4th Edition)
Starting Out with Java: From Control Structures through Objects (6th Edition)
Web Development and Design Foundations with HTML5 (9th Edition) (What's New in Computer Science)
Artificial Intelligence: A Modern Approach
Introduction To Programming Using Visual Basic (11th Edition)
Starting Out with Java: From Control Structures through Data Structures (3rd Edition)
- C++ Array Expander -Just do everything in main and make sure you comment each step Use Pointer Notation for the function and within the function. Use a main function and return the pointer from the ArrayExpander function to mainarrow_forwardWhen a function accepts several arguments, how important is it what order those arguments are sent in?arrow_forwardUnder what circumstances can you successfully return a pointer from a function?arrow_forward
- Object Oriented Programming C++ Language please use commentarrow_forwardWhen an array is passed as an actual parameter to a function, what is actually being passed?arrow_forwardA pointer variable cannot be: A Passed to a function as argument. B B Changed within the funcction. C Returned by a function. D Assigned as an integer value. Darrow_forward
- Create functions using the R language that take five arguments and multiplies them according to the type of object they are: Scalar Vector Matrix Plot each of the functions that you have constructed.arrow_forwardWhen a function accepts several arguments, how important is it what order they are sent in?arrow_forwardNote: Write programs in c language format use in programs (Printf & Scanf)arrow_forward
- Define the term " pointer to function " .arrow_forwardQuestion 4: Funception Write a function (funception) that takes in another function func_a and a number start and returns a function (func_b) that will have one parameter to take in the stop value. func_b should take the following into consideration the following in order: 1. Takes in the stop value. 2. If the value of start is less than 0, it should exit the function. 3. If the value of start is greater than stop, apply func_a on start and return the result. 4. If not, apply func_a on all the numbers from start (inclusive) up to stop (exclusive) and return the product. def funception (func_a, start): "" Takes in a function (function A) and a start value. Returns a function (function B) that will find the product of function A applied to the range of numbers from start (inclusive) to stop (exclusive) >>> def_func_a(num): 111 return num + 1 >>> func_b1 = funception(func_a, 3) >>> func_b1(2) 4 >>> func_b2 = funception(func_a, -2) >>> func_b2(-3) >>> func_b3 = funception (func_a, -1) >>>…arrow_forwardYou can dereference a smart pointer with the * operator. True Falsearrow_forward
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning