Inspect the code and in your own interpretation, describe the reason call to function ChangeIt_1(n) will not change x in main()?

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
  1. Inspect the code and in your own interpretation, describe the reason call to function ChangeIt_1(n) will not change x in main()?
  2. Inspect the code and in your own interpretation, describe the reason parameter n in ChangeIt_2(int *n) is a pointer, and statement in the function is *n = 6 ?
  3. Write a function called void swap with two parameters, which will receive the address of x and y as pointer. The function should swap the value of x and y only if x is larger than y. Print the value of x and y after the function call.
  4. Write a function called double getAverage(int *array, int SIZE), where it accept the array as pointer, and return the average of the array. Print the returned value from this function. Always use *array rather than subscript to access the array value.
#include <iostream>
using namespace std;
3
49 void ChangeIt_1(int n) {
n = 5;
}
5
7
8E void ChangeIt_2(int *n) {
*n = 6;
10
}
11
12 E void ChangeIt_3(int &n) {
13
n = 73
14
}
15
int ChangeIt_4(int n) {
n = 8;
16
17
18
return n;
19
}
20
21 E main(){
int *p;
//declare p as pointer
int x=10, y=7, SIZE=5, data[SIZE]={1,3,2,5,4};
//reference of x
23
24
p=8x;
25
ChangeIt_1(x);
cout « "ChangeIt_1
26
27
« *p « endl;
28
ChangeIt_2(8x);
cout <« "ChangeIt_2
29
: " « *p « endl;
30
31
32
ChangeIt_3(x);
cout « "ChangeIt_3
« *p « endl;
33
34
ChangeIt_4(x);
cout <« "ChangeIt_4
}
35
X =
36
« *p « endl;
37
38
N 22 22
Transcribed Image Text:#include <iostream> using namespace std; 3 49 void ChangeIt_1(int n) { n = 5; } 5 7 8E void ChangeIt_2(int *n) { *n = 6; 10 } 11 12 E void ChangeIt_3(int &n) { 13 n = 73 14 } 15 int ChangeIt_4(int n) { n = 8; 16 17 18 return n; 19 } 20 21 E main(){ int *p; //declare p as pointer int x=10, y=7, SIZE=5, data[SIZE]={1,3,2,5,4}; //reference of x 23 24 p=8x; 25 ChangeIt_1(x); cout « "ChangeIt_1 26 27 « *p « endl; 28 ChangeIt_2(8x); cout <« "ChangeIt_2 29 : " « *p « endl; 30 31 32 ChangeIt_3(x); cout « "ChangeIt_3 « *p « endl; 33 34 ChangeIt_4(x); cout <« "ChangeIt_4 } 35 X = 36 « *p « endl; 37 38 N 22 22
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps

Blurred answer
Knowledge Booster
Functions
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education