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
EBK C HOW TO PROGRAM
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)
- Help and show me how to fix an error? def kwargs_to_args_decorator(*args, **kwargs): This question is meant to test your knowledge of creating a decorator that accepts an arbitrary number of positional and keyword arguments, to decorate a function that accepts an arbitrary number of positional and keyword arguments, and alters the arguments before passing them to the decorated function. When the decorated function is invoked, this decorator should modify the arguments the decorated function receives. This decorator should filter out all positional arguments passed to the decorated function, which are found in the positional arguments passed to the decorator when the decorator was initialized. It should also filter out all keyword arguments with keys that are found in the keyword arguments given to the decorator when the decorator was initialized. After performing the modifications to the arguments, the decorator should invoke the decorated function with the modified arguments and…arrow_forwardIn this part your will have questions about C++ functions with pointers. • Write a function that takes three integer pointer as parameters and calculates sum of all numbers. This function must return the result as a pointer. • Declare a structure about a book which has properties such as name and price etc. Then create a list of book with 5 books. After that define a function that takes this book-list as a pointer and print out list items. • Write a function that calculates total price of the book in the book list (note: take the book-list as a pointer again). Write all function prototypes and test all functions within a single main functions.arrow_forwardThe Problem: Lots of functions return a pointer when returning a goodvalue and NULL on error. We a quick way of testing for NULL.arrow_forward
- PLEASE WRITE THIS IN C Please read the following: Has to have the two functions as stated below, and has to use pointer notation! Include two functions in your program, one which demonstrates the functionality using pointer notation and one which demonstrates the functionality using array indexing. The function prototypes are below: void copyArrayIndexWay(char * const newArray1, const char * const originalArray1); void copyPointerWay(char *newArray2, const char *originalArray2); char originalArray1[] ="COMP10120"; char originalArray2[] = "COMP10110"; Include relevant print statements to explain the difference between the two functions and provide a nice output with the results.. Attached image of full question:arrow_forwardThis exercise assesses the skills required to develop user defined functions, and pointers.Exercise 1Write a C++ program with two user defined functions. The first function named “functionWithArray” takes two user input arguments of character types and return True if first argument is smaller than the second argument (alphabetically) and returns False otherwise. Write the second function named “functionWithPointers” which behaves like the first functions but uses pointers to receive the arguments.You may assume that both character arrays contain only lower-case letters, and no blanks or other nonalphabetic characters. Write a suitable Main function to test these two functions. Sample Output:Enter First String: C++ProgrammingEnter Second String: JavaProgrammingAccording to functionWithArrays: 'c++programming' is smaller than 'javaprogramming'.According to functionWithPointers: 'c++programming' is smaller than 'javaprogramming'.arrow_forwardC++ Programming I: Free Fall Calc In C++ use Functions with Pointers and References Your free fall calculator program will calculate the time it takes an object to fall until it hits the ground. This program requires functions. Place the function prototypes in a file named FallFunctions.h. Create a global constant for ACCELERATION in the .h file, too. Use a comment to define the units for acceleration. Place the associated function implementations in FallFunctions.cpp. Call all functions from main, which is located in your Driver.cpp. In main, you will call the Header function first. Then, start a do another loop. Inside the loop, call the AskHeight function using a reference to height to ask the user for the height of the fall in feet. Next, call the TimeToFall function using a pointer to time to calculate the time it takes the object to fall. Pass time and height to the WriteResults function to write the information in a neatly formatted string. The string is then returned to…arrow_forward
- C code blocks Write the complete function that receives a pointer to a single floating point number as an argument and returns that number after subtracting 100 from it. Define your function in the same way as the given function prototype. Take a look at the "For example" below to see how the function is used in the main function and the expected result. (For interest sake, note that this is a pass-by-reference function call.) #include <stdio.h>#include <stdlib.h>void subtractFunc(float *a);int main(){ float num = 357.900; subtractFunc(&num); printf("%.3f", num); return 0;} //Your answer starts here For example: Test Result float num = 357.900; subtractFunc(&num); printf("%.3f", num); 257.900arrow_forwardC++ ---- (the bold is code)------ Consider the function interface below: bool isSame(int x, double y); Write a line of code that declares a pointer named Funprt that points to this function.arrow_forwardIn a function aFunction, we have 2 values: num1 (float type), num2 (int type) declared locally and assigned to 2.1 and 6. Write code segment to return the two values from function aFunction.arrow_forward
- Is that right?For functions that are flexibly bound, you need pointers or references.arrow_forwardProgramming language C Write your own implementation for the functions above, where the names of the functions will be:my_strcmpmy_strncmpmy_strchrrespectively. In addition, write a program (a function called main (which allows receiving data, runningThe functions you wrote and printing their results.2 Note 1: In the implementation of the standard library for the strchr function, the return value of the function isfrom a pointer type. In the realization that you must write (strchr_my, the function must return an int value, which indicates theThe index of the character from the beginning of the array. If the character is not found, a negative number (minus one) must be returned.Note 2: The following "input word" can be received (where "input word" is defined as a collection of characters betweenTwo "white" characters - space, t, \or n (\by using the scanf command as follows:scanf(“%s”, character_vector_name);;which will cause the next "input word" to be read, into the array whose name…arrow_forwardPlease send me answer within 10 min!! I will rate you good for sure!! Please provide screenshot of code and output with explaination!! Write a C program that implements and tests a function that simulates strcmp function. You should not use functions from <string.h> library. You may use array and/or pointer notation to define the functions. More precisely, you should implement this function: Hint: int myStrcmp (const char *s1, const char *s2) This function compares the string pointed to by s1 to the string pointed to by s2. If the string pointed to by s1 comes before the string pointed to by s2 in dictionary ordering, then -1 is returned. If the string pointed to by s1 is the same as the string pointed to by s2, then 0 is returned (the compare function is case sensitive). Otherwise, 1 is returned. C programarrow_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