Question

In: Computer Science

a) Which lines of code contain operations that change the contents of memory in this program?...

a) Which lines of code contain operations that change the contents of memory in this program?

b) What are those operations?

int main ( void ){

            double dScore1;

            double dScore2;

            double dScore3;

            double dAverage;

            printf("Enter score 1: ");                                             //line 1

            scanf("%lg", &dScore1);                                           //line 2

            printf("Enter score 2: ");                                             //line 3

            scanf("%lg", &dScore2);                                           //line 4

            printf("Enter score 3: ");                                             //line 5

            scanf("%lg", &dScore3);                                           //line 6

            dAverage = (dScore1 + dScore2 + dScore3) / 3.0;    //line 7

            printf("The average is %g\n", dAverage);                 //line 8

            return 0;

}

Solutions

Expert Solution

int main ( void ){

            double dScore1;

            double dScore2;

            double dScore3;

            double dAverage;

            printf("Enter score 1: ");                                             //line 1

            scanf("%lg", &dScore1);                                           //line 2

            printf("Enter score 2: ");                                             //line 3

            scanf("%lg", &dScore2);                                           //line 4

            printf("Enter score 3: ");                                             //line 5

           scanf("%lg", &dScore3);                                           //line 6

            dAverage = (dScore1 + dScore2 + dScore3) / 3.0;    //line 7

            printf("The average is %g\n", dAverage);                 //line 8

            return 0;

}

a) In the above program, line 2 , line 4 and line 6 (marked as green) change the contents of memory.

b) In the scanf() function we are using & (address resolution operator). Now, &dScore1 , &dScore2 and &dScore4 specify the address of dScore1 , dScore2 and dScore3 variables. So, by using scanf() function, user takes the input of dScore1 , dScore2 and dScore3 from the user and store those values in the memory address of dScore1 , dScore2 and dScore3 variables. So, the memory contents of these variables will be changed by these new values (values which are entered by the user as an input).


Related Solutions

1a) If I'm writing a program which involves many insertion and deletion operations, and memory is...
1a) If I'm writing a program which involves many insertion and deletion operations, and memory is not a concern, which of the following should I choose to hold my data? A: linked list B: fixed-size array C: dynamic array D: any of the above 1b) What about if I'm writing a program and I want the program to be flexible on the data with various sizes, and the program also needs to provide fast access to the data? Which of...
(java)Fix the code in this program. Fix lines, add lines… Comment each line that you fixed...
(java)Fix the code in this program. Fix lines, add lines… Comment each line that you fixed … what you did to fix it. import java.util.Scanner; public static void main(String[] args) { // This program Converts grade Points into a Letter grade. int gradePoints == 00; // Declare variable and assign initial value System.out.printl("Enter Grade Points: "; //Input gradePoints; if ( gradePoints >= -42 ) { System.out.println("Grade = A"); } // if true, then ends here, if false drop to next...
Java Code using Queue Write a program that opens a text file and reads its contents...
Java Code using Queue Write a program that opens a text file and reads its contents into a queue of characters, it should read character by character (including space/line change) and enqueue characters into a queue one by one. Dequeue characters, change their cases (upper case to lower case, lower case to upper case) and save them into a new text file (all the chars are in the same order as the original file, but with different upper/lower case) use...
Java Code using Stack Write a program that opens a text file and reads its contents...
Java Code using Stack Write a program that opens a text file and reads its contents into a stack of characters, it should read character by character (including space/line change) and push into stack one by one. The program should then pop the characters from the stack and save them in a second text file. The order of the characters saved in the second file should be the reverse of their order in the first file. Ex input file: Good...
write a program in java that contain a class for botique . data member include code...
write a program in java that contain a class for botique . data member include code , color , size , quantity . your class should contains all accessor and mutator methods , non paraqmetric constructor , parametric constructor , input andvidsplay method
Program in Java code Write a program with total change amount in pennies as an integer...
Program in Java code Write a program with total change amount in pennies as an integer input, and output the change using the fewest coins, one coin type per line. The coin types are Dollars, Quarters, Dimes, Nickels, and Pennies. Use singular and plural coin names as appropriate, like 1 Penny vs. 2 Pennies. .Ex1: If the input is: 0 the output is:    No change            Ex2: If the input is:    45   the output is:   1 Quarter 2 Dimes
C++ Code You will write a program to process the lines in a text file using...
C++ Code You will write a program to process the lines in a text file using a linked list and shared pointers. You will create a class “Node” with the following private data attributes: • Line – line from a file (string) • Next (shared pointer to a Node) Put your class definition in a header file and the implementation of the methods in a .cpp file. The header file will be included in your project. If you follow the...
Please code in C#-Visual Studio Tasks The program needs to contain the following A comment header...
Please code in C#-Visual Studio Tasks The program needs to contain the following A comment header containing your name and a brief description of the program Output prompting the user for the following inputs: Name as a string Length of a rectangle as a double Width of a rectangle as a double Length of a square as an int After accepting user input, the program outputs the following: User name Area of a rectangle with dimensions matching the inputs Area...
Modify the provided code to create a program that calculates the amount of change given to...
Modify the provided code to create a program that calculates the amount of change given to a customer based on their total. The program prompts the user to enter an item choice, quantity, and payment amount. Use three functions: • bool isValidChoice(char) – Takes the user choice as an argument, and returns true if it is a valid selection. Otherwise it returns false. • float calcTotal(int, float) – Takes the item cost and the quantity as arguments. Calculates the subtotal,...
This program is used to split the input based on the delimiter. Change the code below...
This program is used to split the input based on the delimiter. Change the code below so that the parse function should return an array that contains each piece of the word. For example, the input to the function would be something like 'aa:bbbA:c,' which would be a char *. The function's output would then be a char ** where each element in the array is a char *. For this example, it would return some result where result[0] =...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT