Question

In: Computer Science

Correct mistakes in the following program: /* BUG ZONE!!! Example: some common pointer errors */ #include...

Correct mistakes in the following program:

/* BUG ZONE!!!

Example: some common pointer errors */

#include <stdio.h>

main()

{

int i = 57;

float ztran4;

int track[] = {1, 2, 3, 4, 5, 6}, stick[2][2];

int *nsave;

/* Let's try using *nsave as an int variable, and set it to 38 */

*nsave = 38; /* BUG */

nsave = NULL;

*nsave = 38; /* BUG */

nsave = 38; /* BUG */

&nsave = 38; /* BUG */

nsave = &i;

*nsave = 38;

nsave = &ztran4; /* BUG */

nsave = track; /* nsave points at track[0] */

/* Increase track[0] by 1: */

*nsave++; /* BUG */

/* Now point at stick: */

nsave = stick; /* BUG */

nsave = &stick; /* BUG */

nsave = stick[0][0]; /* BUG */

nsave = *stick;

nsave = **stick; /* BUG */

nsave = stick[0];

nsave = &stick[0][0];

nsave = &**stick;

}

Solutions

Expert Solution

#include <stdio.h>

main()

{

int i = 57;

float ztran4;

int track[] = {1, 2, 3, 4, 5, 6}, stick[2][2];

int *nsave;

int q = 38; /*For assigning 38 to variable otherwise it would corrupt other data structures in the program and get errors instead*/

/* Let's try using *nsave as an int variable, and set it to 38 */

nsave = &q; /* BUG */

nsave = NULL;

nsave = &q /* BUG */

nsave = &q; /* BUG */

nsave = &q; /* BUG */

nsave = &i;

*nsave = 38;

void * v= &nsave; /*For assigning different data type pointer*/

v = &ztran4; /* BUG */

nsave = track; /* nsave points at track[0] */

/* Increase track[0] by 1: */

nsave++; /* BUG */

/* Now point at stick: */

int (*nsave)[2] = stick; /* BUG */

int (*nsave)[2] = stick; /* BUG */

int (*nsave)[2] = stick; /* BUG */

nsave = *stick;

nsave = *stick; /* BUG */

nsave = stick[0];

nsave = &stick[0][0];

nsave = &**stick;

}

Hope this helps you. Please give an upvote. Thank you.


Related Solutions

Business Statistics Common Mistakes in Statistical Studies: Top 6 most common statistical errors made by data...
Business Statistics Common Mistakes in Statistical Studies: Top 6 most common statistical errors made by data scientists Data scientists are the rare breed of professionals who can solve the world’s thorniest problems. The data savvy professionals are believed to be a rare combination of statistical and computational ingenuity, however, these data pros are also prone to mistakes. While we have dived into the makings of a data scientists and covered the topic extensively, it is time to train the gaze...
What are some common email mistakes and how can they be avoided?
What are some common email mistakes and how can they be avoided?
Use C language , pointer limit use //#include <stdio.h> //#include <stdlib.h> //#include <time.h> For example, I...
Use C language , pointer limit use //#include <stdio.h> //#include <stdlib.h> //#include <time.h> For example, I have random array [4,2,7,1,9,8,0]. Sort the array's index but cannot change the position of item in the array, if you copy the array to a new array, you also cannot change the item's position in array. The index now is[0,1,2,3,4,5,6] The output should be[6,3,1,0,2,5,4]
Correct all errors in the provided script. Remember that some errors are fatal (result in an...
Correct all errors in the provided script. Remember that some errors are fatal (result in an error message) while others simply cause the program to produce incorrect results. You can assume that you have fixed all errors when the checker passes all tests. %*************************************************************************************** %It is recommended that you debug this program offline and submit only once you have corrected the errors %*************************************************************************************** %% %These 3 loops all calculate the sum of the integers from 1 through 1000 for number...
Identify errors and correct them of the following Java program : 1. import java.utility.Random; 2. 3....
Identify errors and correct them of the following Java program : 1. import java.utility.Random; 2. 3. public class Sequen 4. 5. private int stand 6. private int calc; 7. 8. public Sequen(int numStand) 9. { 10. stand = numStand; 11. skip; 12. } 13. 14. public void skip() 15. { 16. Random sit = new Random(); 17. calc = sit.nextInt(stand) + 1; 18. } 19. 20. public getStand() 21. { 22. return stand; 23. } 24. 25. int getCalc() 26....
List some of the common mistakes that your organization has made as it relates to organizational...
List some of the common mistakes that your organization has made as it relates to organizational behavior.
With example, discuss the common bias/errors under inductive reasoning?
With example, discuss the common bias/errors under inductive reasoning?
1.The below code has some errors, correct the errors and post the working code. Scanner console...
1.The below code has some errors, correct the errors and post the working code. Scanner console = new Scanner(System.in); System.out.print("Type your name: "); String name = console.nextString(); name = toUpperCase(); System.out.println(name + " has " + name.Length() + " letters"); Sample Ouptut: Type your name: John JOHN has 4 letters    2. Write a code that it reads the user's first and last name (read in the entire line as a single string), then print the last name   followed by...
Identify errors and correct them of the following Java program: 1. import java.utility.Random; 2.   3. public...
Identify errors and correct them of the following Java program: 1. import java.utility.Random; 2.   3. public class Sequen 4.   5. private int stand   6. private int calc;   7.   8. public Sequen(int numStand) 9. { 10.         stand = numStand; 11.         skip; 12.         } 13.           14.         public void skip() 15.         { 16.         Random sit = new Random(); 17.         calc = sit.nextInt(stand) + 1; 18.         } 19.           20.         public getStand() 21.         { 22.         return stand; 23.         } 24.           25.         int getCalc() 26.         { 27.         return calc; 28.         } 29.         } Identify 5 other errors and give their Line Number, Error...
Identify errors and correct them of the following Java program: 1. import java.utility.Random; 2.   3. public...
Identify errors and correct them of the following Java program: 1. import java.utility.Random; 2.   3. public class Sequen 4.   5. private int stand   6. private int calc;   7.   8. public Sequen(int numStand) 9. { 10.         stand = numStand; 11.         skip; 12.         } 13.           14.         public void skip() 15.         { 16.         Random sit = new Random(); 17.         calc = sit.nextInt(stand) + 1; 18.         } 19.           20.         public getStand() 21.         { 22.         return stand; 23.         } 24.           25.         int getCalc() 26.         { 27.         return calc; 28.         } 29.         } One error is already identified for you as shown below:...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT