Question
Write a program in C that prints the values in an array and the addresses of the array's elements using four different techniques, as follows:
Write a program in C that prints the values in an array and the addresses of the array's elements using four
different techniques, as follows:
1. Array index notation using array name
2. Pointer/offset notation using array name
3. Array index notation using a pointer
4. Pointer/offset notation using a pointer
Example fig07_20.c and the lab for this week will be useful guides for this assignment.
Learning Objectives
In this assignment:
Use functions with array and pointer arguments
Use indexing and offset notations to access arrays
Requirements
Your code must use these eight functions, using these names (in addition to main):
1. valuesNameIndex
2. valuesPointerIndex
3. valuesNameOffset
4. valuesPointerOffset
5. addressesNameIndex
6. addressesPointerIndex
7. addressesNameOffset
8. addressesPointerOffset
Requirements for the valuesNameIndex Function
Purpose: This function prints the values in the array.
Parameter: integer array (square bracket notation)
Algorithm: Print the name of the function, then print the values of the input array using a
loop with array index notation. Use the symbolic constant. You must use the
parameter. Do not declare any other variables except a loop control variable.
Return value: None
Requirements for the valuesPointerIndex Function
Purpose: This function prints the values in the array.
Parameter: Pointer to an int array
Algorithm: Print the name of the function, then print the values of the input array using a loop with
pointer index notation. Use the symbolic constant. You must use the parameter. Do not
declare any other variables except a loop control variable.
Return value: None
Requirements for the valuesNameOffset Function
Purpose: This function prints the values in the array.
Parameter: integer array (square bracket notation)
Algorithm: Print the name of the function, then print the values of the input array using a loop with
pointer offset notation using the array name. Use the symbolic constant. You must use
the parameter. Do not declare any other variables except a loop control variable.
Return value: None
Requirements for the valuesPointerOffset Function
Purpose: This function prints the values in the array.
Parameter: Pointer to an int array
Algorithm: Print the name of the function, then print the values of the input array using a loop with
pointer offset notation using the pointer. Use the symbolic constant. You must use the
parameter. Do not declare any other variables except a loop control variable.
Return value: None
Requirements for the addressesNameIndex Function
Purpose: This function prints the address of each element of the array.
Parameter: integer array (square bracket notation)
Algorithm: Print the name of the function, then print the address of each element of the array
using a loop with array index notation. Use the symbolic constant. You must use the
parameter. Do not declare any other variables except a loop control variable. Use the
appropriate format control string for printing addresses.
Return value: None
Requirements for the addressesPointerIndex Function
Purpose: This function prints the address of each element of the array.
Parameter: Pointer to an int array
Algorithm: Print the name of the function, then print the address of each element of the array
using a loop with pointer index notation. Use the symbolic constant. You must use the
parameter. Do not declare any other variables except a loop control variable. Use the
appropriate format control string for printing addresses.
Return value: None
Requirements for the addressesNameOffset Function
Purpose: This function prints the address of each element of the array.
Parameter: integer array (square bracket notation)
Algorithm: Print the name of the function, then print the address of each element of the array
using a loop with pointer offset notation using the array name. Use the symbolic
constant. You must use the parameter. Do not declare any other variables except a loop
control variable. Use the appropriate format control string for printing addresses.
Return value: None
Requirements for the addressesPointerOffset Function
Purpose: This function prints the address of each element of the array.
Parameter: Pointer to an int array
Algorithm: Print the name of the function, then print the address of each element of the array
using a loop with pointer offset notation using the pointer. Use the symbolic constant.
You must use the parameter. Do not declare any other variables except a loop control
variable. Use the appropriate format control string for printing addresses.
Return value: None
Requirements for main:
1. Declare and initialize an integer array of size 5, using the values 25, 35, 45, 55 & 65.
2. Call each function with the appropriate argument.
Other Requirements for this Program
No other variables should be declared in main, above main, in any function, or in any function
parameter list except those explicitly noted in the instructions.
You must a symbolic constant for the array size wherever it is needed.
All output must display exactly as it appears in the sample run. Note that your actual addresses may
differ.
Sample Run
Printing array values from function valuesNameIndex
arrayName[0] = 25
arrayName[1] = 35
arrayName[2] = 45
arrayName[3] = 55
arrayName[4] = 65
Printing array values from function valuesPointerIndex
arrayName[0] = 25
arrayName[1] = 35
arrayName[2] = 45
arrayName[3] = 55
arrayName[4] = 65
Printing array values from function valuesNameOffset
arrayName[0] = 25
arrayName[1] = 35
arrayName[2] = 45
arrayName[3] = 55
arrayName[4] = 65
Printing array values from function valuesPointerOffset
arrayName[0] = 25
arrayName[1] = 35
arrayName[2] = 45
arrayName[3] = 55
arrayName[4] = 65
Printing array addresses from function addressesNameIndex
&arrayName[0] = 62fe00
&arrayName[1] = 62fe04
&arrayName[2] = 62fe08
&arrayName[3] = 62fe0c
Step by Step Solution
3.44 Rating (157 Votes )
There are 3 Steps involved in it
Step: 1
Heres the implementation of the C program as per the provided requirements include define SIZE 5 void valuesNameIndexint arrayName void valuesPointerI...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started