Question

Make one program using Dev c++, and explain how program works Final Program Requirements: Declare an...

Make one program using Dev c++, and explain how program works

Final Program Requirements:

Declare an int variable and int array with four elements in the main program. Initial values for the intvariable and int array are hardcoded in the program.

Declare an int pointer in the main program.Program shows the values of the integer variable and integer arrayelements.

Program shows the addresses of the variable and each integer array element. Store addresses inpointers temporarily prior to displaying. The addresses can change whenever the program is run.

Program asks the user to enter an address. The addressis stored in a temporary int variable, and thencopied to the integer pointer.

Program asks for an integer value X. Using derefencing, the program changes the value pointed by thepointer address entered by the user to X.

Program asks if the user wants torun the program again.

Test Walkthrough

1. Enter an address. (The address should be one of the addresses shown in the program. Entering an invalidaddress is very dangerous, may cause the program to hang, or worse, cause the computer to stop responding.)

2. Enter an integer value.

3. Repeat steps 1 and 2 until the integer variable and integer array elements are all changed.

4. Enter an invalid choice.

5. Quit the program.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

#include<iostream>
using namespace std;
int main()
{
   int i;
   int arr[4];
   arr[0]=100;
   arr[1]=200;
   arr[2]=300;
   arr[3]=400;
   i=1;
   int *p;
   p=&i;
   cout<<"value of variable i is "<<*p<<endl<<endl;
   cout<<"Address of variable i is "<<p<<endl<<endl;
   std::cout<<"address in unsigned integer " << reinterpret_cast<unsigned int>(p)<<endl;
   p=&arr[0];
   int cnt=0;
   cout<<" value and address of Array elements are"<<endl;
   while(cnt<=3)
   {
       cout<<"value "<<*p<<endl;
       cout<<"Address "<<p<<endl;
       p++;
       cnt++;
   }
  

   return 0;
}

Add a comment
Know the answer?
Add Answer to:
Make one program using Dev c++, and explain how program works Final Program Requirements: Declare an...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Make one program using Dev c++, and explain how program works Final Program Requirements: Program is...

    Make one program using Dev c++, and explain how program works Final Program Requirements: Program is a modified version of the collection of formulas from Nested Conditional and IterativeStatements. Convert the formulas previously done in the collection of formulas to equivalent functions. Program can be subdivided into smaller units by creating functions that compute for different variables. Requirements from Nested Conditional and Iterative Statements apply. Test Walkthrough 1. Select a formula from the formula selection screen. 2. Select a variable...

  • Please code in c 1. Write a program which does the following: Declare and initialize three...

    Please code in c 1. Write a program which does the following: Declare and initialize three pointers. One points to an integer, one points to a float and one points to a character variable Ask the user to enter appropriate values for these variables. Output the values to the screen by accessing the variables directly and then by using pointer references. Print the address of each variable. Modify the variables by performing any arithmetic operation only using pointer refer- ences...

  • C++ pointers and linked lists 1. Declare an integer pointer variable intPointer. Initialize it to point...

    C++ pointers and linked lists 1. Declare an integer pointer variable intPointer. Initialize it to point to an int variable named someInt. Assign the value 451 to someInt and output (cout) the variable someInt and output (cout) the value pointed to by intPointer. Write an assignment statement that indirectly stores 900 into the value pointed to by intPointer. Output (cout) the value pointed to by intPointer and output (cout) the variable someInt, 2. Declare a pointer variable charArrPointer and initialize...

  • Using C programming

    Using C, create a data file with the first number being an integer. The value of that integer will be the number of further integers which follow it in the file. Write the code to read the first number into the integer variable how_many.Please help me with the file :((This comes from this question:Write the code to dynamically allocate ONE integer variable using calloc (contiguous allocation) or malloc (memory allocation) and have it pointed to by a pointer (of type int...

  • *Answer must be in C* Write a complete program as follows (declare any necessary variables): Create...

    *Answer must be in C* Write a complete program as follows (declare any necessary variables): Create an array of doubles named “hummus” with 2 rows and 300 columns. Initialize all array elements to zero. Write a loop that will repeatedly ask the user to enter a value and store it in the first row of the array (do not overwrite previously entered values) until the whole first row is populated with the user input. (hint the loop should have the...

  • Write the code to dynamically allocate ONE integer variable using calloc (contiguous allocation) or malloc (memory...

    Write the code to dynamically allocate ONE integer variable using calloc (contiguous allocation) or malloc (memory allocation) and have it pointed to by a pointer (of type int * ) named ptr_1. Use ptr_1 to assign the number 7 to that dynamically allocated integer, and in another line use printf to output the contents of that dynamically allocated integer variable. Write the code to dynamically allocate an integer array of length 5 using calloc or malloc and have it pointed...

  • // Enter your name as a comment for program identification // Program assignment TripCost.cpp // Enter...

    // Enter your name as a comment for program identification // Program assignment TripCost.cpp // Enter your class section, and time /* The program TripCost.cpp uses pointers to calculate    the cost of a trip depending on the cost of a gallon    of gas, the number of miles, and the number of miles    per gallon a car gets. */ /* The cost of gas, the number of miles, and number of    miles per gallon is entered. */...

  • Write a complete C++ program that will: Declare a vector of integers Use a pointer to...

    Write a complete C++ program that will: Declare a vector of integers Use a pointer to dynamically allocate an array of 10 elements Ask the user how many values they would like to have in the data structures Read in the user’s response and make sure that it is greater than 20 (error loop) Generate the number of integers that the user asked for and store them into both data structures. The integer values should be unique unordered values (no...

  • Please answer using C ++ programming language ONLY! We have only used <stdio.h> if that helps....

    Please answer using C ++ programming language ONLY! We have only used <stdio.h> if that helps. This is a basic course and the furthest we have gone is BASIC arrays. Write the code for the following problems using arrays. Write what would go in the “int main()” part of the program. For these problems, the entire program and program output is not needed. Just include what goes in the int main() part of the program. 1. Declare an integer array...

  • Homework Part 1 Write a C program that declares and initializes a double, an int, and a char. You...

    Homework Part 1 Write a C program that declares and initializes a double, an int, and a char. You can initialize the variables to any legal value of your choosing. Next, declare and initialize a pointer variable to each of the variables Using printf), output the following: The address of each of the first three variables. Use the "Ox%x" format specifier to print the addresses in hexadecimal notation The value of each variable. They should equal the value you gave...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT