Question
CODE IN C Objective Create a program that will initialize regular variables, initialize pointers that will point to those variables, and dereference those pointers to
- CODE IN C
- Objective
- Create a program that will initialize regular variables, initialize pointers that will point to those variables, and dereference those pointers to modify the values of the variables.
- How to create, output, and dereference a pointer.
- How to use a dereferenced pointer to change the value of a variable.
- Related SLO
- Develop properly structured multifile programs with automatic compilation.
- Implement pointers and character variables in C.
- Instructions
- Create a makefile namedmakefilethat will automatically compile, link, and create an executable for this assignment.
- This assignment will not require any external files such as getdouble.c, getdouble.h
- Do NOT submit a makefile with any other name.
- Note: This program has no user input.
- Declare and initialize a char variable. Use a letter, upper or lowercase, as the initial value.
- Declare and initialize an integer variable. Use a number other than 0 as the initial value.
- Declare and initialize a double variable. Use a number other than 0 as the initial value.
- Output the variable names along with their values.
- Declare and initialize a char pointer that points to the address of the char variable from above.
- Declare and initialize an integer pointer that points to the address of the integer variable from above.
- Declare and intialize a double pointer that points to the address of the double variable from above.
- Output the pointer names along with their values. Use the format specifier %p for printing pointer values.
- Ensure that the output are hexadecimal numbers before proceeding.
- 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.
- You MUST use the pointer to display the value of the variable.
- Dereference the char pointer to display the character value.
- Dereference the int pointer to display the integer value.
- Dereference the double pointer to display the double value.
- To use a pointer to modify the variable, you must dereference the pointer.
- In other words, dereferenced pointer = dereferenced pointer + 4
- The output should show that the letter and numbers are increased by 4.
- The output should show that the letter and numbers are increased by 4.
- Be clear with your comments and output to the user, so I can understand what you're program is doing.
- Be sure to have read through the assignment policy for this class.
% make
% ./program
Variable values:
charVariable = f
intVariable = 5
doubleVariable = 3.140000
Pointer names and addresses stored:
charPointer = 0x7ffee35de1d7
intPointer = 0x7ffee35de1d0
doublePointer = 0x7ffee35de1c8
Pointer names and values using dereferencing:
dereferenced charPointer = f
dereferenced intPointer = 5
dereferenced doublePointer = 3.140000
Pointer names and values using dereferencing after + 4:
dereferenced charPointer = j
dereferenced intPointer = 9
dereferenced doublePointer = 7.140000
Variable values:
charVariable = j
intVariable = 9
doubleVariable = 7.140000
Step by Step Solution
There are 3 Steps involved in it
Step: 1
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