Your Question: Objective Create a program that will initialize an array, initialize a pointer to that array, and output the contents and address of the array in various ways. Create a call-by-reference function to modify a variable that's been declared in the main() function by passing the variable's address to the function. How to create, output, and dereference a pointer. How to use a dereferenced pointer to change the value of a variable. Instructions Create a program named LastnameFirstname13.c, that does the following: Note: This program has no user input. Declare and initialize an integer array of size 5. Initialize each element with a value other than 0. Declare and initialize an integer pointer that points to the address of the integer array above. Declare and initialize an integer variable. Use an initial value other than 0. Later in the program, this variable will be used in a call-by-reference function that modifies the value without returning a value. Output the last element in the array in the following four ways: Using array subscript notation with the array name Using pointer/offset notation with the array name Using array subscript notation with the pointer Using pointer/offset notation with the pointer Output the contents of the array in the following four ways: Using array subscript notation with the array name Using pointer/offset notation with the array name Using array subscript notation with the pointer Using pointer/offset notation with the pointer Output the addresses of each element in the array using array subscript notation with the array name NOTE: The C compiler on UH UNIX has been updated to automatically add the 0x prefix when using the format specifier %p. You do not need to manually type the 0x prefix. Create the following custom function given its prototype and description: Declare the function prototype above main and the function definition below main. void increaseIntViaPointer(int *); A call-by-reference function that will increase the value of the integer that the parameter pointer points to. At the beginning of the function, output a message to tell the user that execution is inside the function and that the parameter is about to be modified by 100. Increase the integer value that the pointer points to by 100. In other words, dereference the parameter pointer and increase the integer value by 100. At the end of the function, output another message to show the new integer value by dereferencing the pointer. Back in the main() function, output a message showing the initial state of the variable before calling the custom function. Call increaseIntViaPointer() and pass in the address of the integer variable that was created at the beginning of the program. Output another message showing the final state of the variable after calling the custom function. Use the Example Output to format your output the same way. All output should be clear in what and how it is being displayed. Be sure to have a program description at the top and in-line comments. Be clear with your comments and output to the user, so I can understand what you're program is doing. attached is an example output

Programming Logic & Design Comprehensive
9th Edition
ISBN:9781337669405
Author:FARRELL
Publisher:FARRELL
Chapter6: Arrays
Section: Chapter Questions
Problem 18RQ
icon
Related questions
Question
Your Question:
  • Objective
    • Create a program that will initialize an array, initialize a pointer to that array, and output the contents and address of the array in various ways.
    • Create a call-by-reference function to modify a variable that's been declared in the main() function by passing the variable's address to the function.
    • How to create, output, and dereference a pointer.
    • How to use a dereferenced pointer to change the value of a variable.
  • Instructions
    • Create a program named LastnameFirstname13.c, that does the following:
      1. Note: This program has no user input.
      2. Declare and initialize an integer array of size 5. Initialize each element with a value other than 0.
      3. Declare and initialize an integer pointer that points to the address of the integer array above.
      4. Declare and initialize an integer variable. Use an initial value other than 0.
        • Later in the program, this variable will be used in a call-by-reference function that modifies the value without returning a value.
      5. Output the last element in the array in the following four ways:
        1. Using array subscript notation with the array name
        2. Using pointer/offset notation with the array name
        3. Using array subscript notation with the pointer
        4. Using pointer/offset notation with the pointer
      6. Output the contents of the array in the following four ways:
        1. Using array subscript notation with the array name
        2. Using pointer/offset notation with the array name
        3. Using array subscript notation with the pointer
        4. Using pointer/offset notation with the pointer
      7. Output the addresses of each element in the array using array subscript notation with the array name
        • NOTE: The C compiler on UH UNIX has been updated to automatically add the 0x prefix when using the format specifier %p. You do not need to manually type the 0x prefix.
      8. Create the following custom function given its prototype and description:
        Declare the function prototype above main and the function definition below main.
        • void increaseIntViaPointer(int *);
          • A call-by-reference function that will increase the value of the integer that the parameter pointer points to.
          • At the beginning of the function, output a message to tell the user that execution is inside the function and that the parameter is about to be modified by 100.
          • Increase the integer value that the pointer points to by 100. In other words, dereference the parameter pointer and increase the integer value by 100.
          • At the end of the function, output another message to show the new integer value by dereferencing the pointer.
      9. Back in the main() function, output a message showing the initial state of the variable before calling the custom function.
      10. Call increaseIntViaPointer() and pass in the address of the integer variable that was created at the beginning of the program.
      11. Output another message showing the final state of the variable after calling the custom function.
      12. Use the Example Output to format your output the same way.
        • All output should be clear in what and how it is being displayed.
      13. Be sure to have a program description at the top and in-line comments.
        • Be clear with your comments and output to the user, so I can understand what you're program is doing.
  • attached is an example output
• Example Output
*** Please pay attention to your variable and pointer names. If you use different variable and pointer names, it should be
reflected in your program's output. When printing the addesses of each element in the array, your addresses will likely be
different. ****
% make
% ./program
Printing the last element in the array:
intArray[4] = 17
*(intArray + 4) = 17
intArrayPointer [4] = 17
*(intArrayPointer + 4) = 17
Printing the contents of the array:
Using array subscript notation with array name...
13, 72, 88, 100, 17
Using pointer/offset notation with array name...
13, 72, 88, 100, 17
Using array subscript notation with pointer...
13, 72, 88, 100, 17
Using pointer/offset notation with pointer...
13, 72, 88, 100, 17
Printing the addresses of each element in the array:
&intArray [0]
0x7fff17f16140
&intArray[1]
0x7fff17f16144
&intArray[2] = 0x7fff17f16148
0x7fff17f1614c
&intArray[3]
&intArray[4] =0x7fff17f16150
Integer variable BEFORE function call...
intVariable = 10
Inside increaseIntViaPointer() function, increasing parameter by 100...
*intParam= 110
Integer variable AFTER function call...
intVariable = 110
• Hints
• The Example Output should give you a good indication of how to output the values in the specified way.
o Use the format specifier %p when printing addresses.
• Don't forget to declare the function prototype above the main() function.
Transcribed Image Text:• Example Output *** Please pay attention to your variable and pointer names. If you use different variable and pointer names, it should be reflected in your program's output. When printing the addesses of each element in the array, your addresses will likely be different. **** % make % ./program Printing the last element in the array: intArray[4] = 17 *(intArray + 4) = 17 intArrayPointer [4] = 17 *(intArrayPointer + 4) = 17 Printing the contents of the array: Using array subscript notation with array name... 13, 72, 88, 100, 17 Using pointer/offset notation with array name... 13, 72, 88, 100, 17 Using array subscript notation with pointer... 13, 72, 88, 100, 17 Using pointer/offset notation with pointer... 13, 72, 88, 100, 17 Printing the addresses of each element in the array: &intArray [0] 0x7fff17f16140 &intArray[1] 0x7fff17f16144 &intArray[2] = 0x7fff17f16148 0x7fff17f1614c &intArray[3] &intArray[4] =0x7fff17f16150 Integer variable BEFORE function call... intVariable = 10 Inside increaseIntViaPointer() function, increasing parameter by 100... *intParam= 110 Integer variable AFTER function call... intVariable = 110 • Hints • The Example Output should give you a good indication of how to output the values in the specified way. o Use the format specifier %p when printing addresses. • Don't forget to declare the function prototype above the main() function.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Functions
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
Programming with Microsoft Visual Basic 2017
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:
9781337102124
Author:
Diane Zak
Publisher:
Cengage Learning