Concept explainers
Each of the following declarations and program segments has errors. Locate as many as you can.
A) int ptr*;
B) int x, *ptr;
&x = ptr;
C) int x, *ptr;
*ptr = &x;
D) int x, *ptr;
ptr = &x;
ptr =100; // Store 100 in x
cout << x << endl;
E) int numbers[] = {10, 20, 30, 40, 50};
cout << "The third element in the array is ";
cout << *numbers + 3 << endl;
F) int values[20], *iptr;
iptr = values;
iptr *= 2;
G) double level;
int dPtr = &level;
H) int *iptr = &ivalue;
int ivalue;
I) void doubleVal (int val)
{
*val *= 2;
}
J) int *pint;
new pint;
K) int *pint;
pint = new int;
pint = 100;
L) int *pint;
pint = new int[100]; // Allocate memory
.
.
Process the array
.
.
delete pint; // Free memory
delete pint; // Free memory
M) int *getNum()
{
int wholeNum;
cout << "Enter a number: ";
cin >> wholeNum;
return SwholeNum;
}
N) unique_ptr u = new unique_ptr(new int);
O) unique_ptr<int> u = make_unique<int>();
unique_ptr<int> v;
v = u;
P) unique_ptr<int>u(new int);
unique_ptr<int>v;
v.reset(u);
Want to see the full answer?
Check out a sample textbook solutionChapter 10 Solutions
Starting Out With C++: Early Objects (10th Edition)
Additional Engineering Textbook Solutions
Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
Programming in C
Computer Science: An Overview (12th Edition)
Computer Science: An Overview (13th Edition) (What's New in Computer Science)
Software Engineering (10th Edition)
Starting Out with Programming Logic and Design (4th Edition)
- be recor #include #include minutes #include limit on int func(int, int, int, int); main(){ srand(time(NULL)); int a, b, c, fNum; printf("Choose three different numbers between 0-39:"); scanf ("%d%d%d", &a, &b, &c); fNum = func (a, b, c, 25); printf("\nThe result: %d", fNum); } int func (int ul, int u2, int u3, int iter){ srand (time (NULL)); int n1=0, i=0, count=0; for (;iarrow_forwardQ 6:- Specify the local and Global variables used in the code below and express the reason r'. #include int a=10,b; void main() { printf("a = 8d and b=%d“,a,b) ; #include void main() { int x-23, y-4; printf("x = %d and y=sd“,x,y);arrow_forwardFilling the Pool (Deprecated) Write a program that calculates the time neccessary to completely fill an empty pool with water. We will assume that the pool is rectangular and the depth is uniform. All input values in this program will be integers. Prompt the user to enter the pool dimensions - length, width, and depth (unit: feet) - as well as the rate at which water can be put into the pool (unit: gallons per minute). Using these values, calculate and display the time (in minutes) needed to fill the pool from completely empty to completely full. Note: you should calculate the volume of the pool (as cubic feet) and then determine the rate (in cubic feet per minute) that water can be put into the pool. Assume that there are 7.48 gallons in one cubic foot. Your program should run like the examples shown below: Enter pool dimensions Length: 10 Width: 8 Depth: 7 Water entry rate: 14 The pool will fill completely in 299.2 minutesarrow_forwardI assume the following 2 codes express the same meaning? int myvar; int * myptr = &myvar; and int myvar; int * myptr; myptr = &myvar;arrow_forwardVoid Do1 (int: &, a. int &b) { a = 5; a = a + b; b = a + 2; } Int main() { Int x = 10; Do1 (x,x); Cout << x << endl; } The output of this program isarrow_forwardWhen you perform arithmetic operations with operands of different types, such as adding an int and a float, ____________. C# chooses a unifying type for the result you must choose a unifying type for the result you must provide a cast you receive an error messagearrow_forwardMark the following statements as true or false: a. To use a predefined function in a program, you need to know only the name of the function and how to use it. (1) b. A value-returning function returns only one value. (2, 3) c. Parameters allow you to use different values each time the function is called. (2, 7, 9) d. When a return statement executes in a user-defined function, the function immediately exits. (3, 4) e. A value-returning function returns only integer values. (4) f. A variable name cannot be passed to a value parameter. (3, 6) g. If a C++ function does not use parameters, parentheses around the empty parameter list are still required. (2, 3, 6) h. In C + + , the names of the corresponding formal and actual parameters must be the same. (3, 4, 6) i. A function that changes the value of a reference parameter also changes the value of the actual parameter. (7) j. Whenever the value of a reference parameter changes, the value of the actual parameter changes. (7) k. In C++, function definitions can be nested; that is, the definition of one function can be enclosed in the body of another function. (9) l. Using global variables in a program is a better programming style than using local variables, because extra variables can be avoided. (10) m. In a program, global constants are as dangerous as global variables. (10) n. The memory for a static variable remains allocated between function calls. (11)arrow_forwardCoin Toss Write a function named coinToss that simulates the tossing of a coin. When you call the function, it should generate a random number in the range of 1 through 2. If the random number is 1, the function should display "heads". If the random number is 2, the function should display "tails". Demonstrate the function in a program that sks the user how many times the coin should be tossed and the coin then simulates the tossing of the coin that number of times.arrow_forwardEach of the following definitions and program segments has errors. Locate as many as you can and correct the errors. a) void showValues (int nums) { for (int i = 0; i<8; i++) cout<arrow_forwardarrow_back_iosSEE MORE QUESTIONSarrow_forward_iosRecommended textbooks for you
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningC++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,
C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningC++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,