Question

In: Computer Science

Integer Pointers Program and Analysis Demonstrate an understanding of basic C++ programming concepts by completing the...

Integer Pointers Program and Analysis

Demonstrate an understanding of basic C++ programming concepts by completing the following:

  • Program: Create a C++ program that asks the user to enter three integer values as input. Store the values into three different variables. For each variable, create three integer pointers that point to each value. Display the contents of the variables and pointers. In your program, be sure to use the new operator and delete operators to management memory.
  • Program Analysis: Given your program implementation, discuss and identify the possible security vulnerabilities that may exist. If present, discuss solutions to minimize the vulnerabilities. Discuss and identify possible problems that can result in errors when using integer pointers. Your analysis should be 1-2 pages in length.

Solutions

Expert Solution

Hello,

Please go through code and output.

CODE:

#include <iostream>
using namespace std;


int main()
{
   int v1 = 0, v2 = 0, v3 = 0; // initialize variables
   int *p1 = NULL, *p2 = NULL, *p3 = NULL; // initialize pointers
   cout << "Enter three integer values: " << endl; // ask user to enter number
   cin >> v1 >> v2 >> v3;
/* give memory to pointers */
   p1 = new int[1];
   p2 = new int[1];
   p3 = new int[1];

/* assign value to pointers */
   p1[0] = v1;
   p2[0] = v2;
   p3[0] = v3;

/* print value */
   cout << "v1 : " << v1 << endl;
   cout << "v2 : " << v2 << endl;
   cout << "v3 : " << v3 << endl;
   cout << "p1 : " << p1[0] << endl;
   cout << "p2 : " << p2[0] << endl;
   cout << "p3 : " << p3[0] << endl;

/* delete allocated memory */
   delete p1;
   delete p2;
   delete p3;

}

OUTPUT:

------------------------------------------------------------------------------------------------

In this program, we can see some of the problems can occur if we will not handle it.

1. p1, p2, p3 should allocate memory before assign value to it.

if we will not do it. segmentation fault will occur.

2. If we assign memory to pointer it should be free also.

If this not happen memory leak problem will occur.

3. after deleting the memory we need to assign null to the pointer.

If this will not happen sometime that pointer will still be pointing to that address and program will behave differently.


Related Solutions

a summary explaining the basic understanding of the following programming concepts using a language of python:...
a summary explaining the basic understanding of the following programming concepts using a language of python: •Variables •Arithmetic and Logical operations •Sequential coding (Structured programming •Decision structure (If statements) •Repetition structure •Functions with some coding demos inside visual studio code python IDE which can be sent as screenshot. preferably a typed summary please which can be written into powerpoint pleaseeeee ???
WITHOUT USING POINTERS. This is C programming. I am writing a program which should calculate standard...
WITHOUT USING POINTERS. This is C programming. I am writing a program which should calculate standard deviation of an array of exam scores and then add the standard deviation to each array element. It should print the original array, the standard deviation, and the new rounded adjusted array. I included my question as a comment in the line of code that is giving me an issue. (Removing the a from E-x-a-m as Chegg doesn't allow the word.) #include <stdio.h> #include...
Description The purpose of this assignment is to demonstrate understanding of basic alterations in vision and...
Description The purpose of this assignment is to demonstrate understanding of basic alterations in vision and hearing. Compose a short (1.5 – 2.5 page) essay explaining one common alteration in vision and one common alteration in hearing. You should briefly describe the pathophysiologic changes, prevalence, manifestations, and treatment for each. You should also explain the mechanism that the specific treatment uses to return a normal functioning state. You may select a disease process from the book, but will need to...
this program is to be done in c language. Using Pointers Create a program pointerTester.c to...
this program is to be done in c language. Using Pointers Create a program pointerTester.c to experiment with pointers. Implement the following steps one by one in your program: YOU NEED TO ANSWER QUESTION Use printf to print your answers at the end(after 12). 1. Declare three integer variables a, b and c. Initialize them to 0, 100 and 225, respectively. 2. Print the value of each variable and its address. 3. Add the following declaration to your code: int...
Demonstrate your understanding of utility maximization with a story that incorporates the concepts of the utility....
Demonstrate your understanding of utility maximization with a story that incorporates the concepts of the utility. A story consists of 200 - 300 words.
Create a basic program (C programming language) that accomplishes the following requirements: Allows the user to...
Create a basic program (C programming language) that accomplishes the following requirements: Allows the user to input 2 numbers, a starting number x and ending number y Implements a while loop that counts from x (start) to y(end). Inside the loop, print to the screen the current number Print rather the current number is even or odd If the number is even , multiply by the number by 3 and print the results to the screen. If the number is...
Demonstrate an understanding of the purpose of an outreach program along with services that could be...
Demonstrate an understanding of the purpose of an outreach program along with services that could be provided. What are the potential types of outreach programs that could be implemented? How do the various strategies for implementing an outreach program impact the quality of testing?
C programming Write a function called string in() that takes two string pointers as arguments. If...
C programming Write a function called string in() that takes two string pointers as arguments. If the second string is contained in the first string, have the function return the address at which the contained string begins. For instance, string in(“hats”, “at”) would return the address of the a in hats. Otherwise, have the function return the null pointer. Test the function in a complete program that uses a loop to provide input values for feeding to the function.
The C function funsum below takes three arguments -- an integer val and two function pointers...
The C function funsum below takes three arguments -- an integer val and two function pointers to functions f and g, respectively. f and g both take an integer argument and return an integer result. The function funsum applies f to val, applies g to val, and returns the sum of the two results. Translate to RISC-V following RISC-V register conventions. Note that you do not know, nor do you need to know, what f and g do, nor do...
The C function funsum below takes three arguments -- an integer val and two function pointers...
The C function funsum below takes three arguments -- an integer val and two function pointers to functions f and g, respectively. f and g both take an integer argument and return an integer result. The function funsum applies f to val, applies g to val, and returns the sum of the two results. Translate to RISC-V following RISC-V register conventions. Note that you do not know, nor do you need to know, what f and g do, nor do...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT