Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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.
  1. This assignment will not require any external files such as getdouble.c, getdouble.h
  2. Do NOT submit a makefile with any other name.
  • Create a program namedLastnameFirstname12.c, that does the following:
    1. Note: This program has no user input.
    2. Declare and initialize a char variable. Use a letter, upper or lowercase, as the initial value.
    3. Declare and initialize an integer variable. Use a number other than 0 as the initial value.
    4. Declare and initialize a double variable. Use a number other than 0 as the initial value.
    5. Output the variable names along with their values.
    6. Declare and initialize a char pointer that points to the address of the char variable from above.
    7. Declare and initialize an integer pointer that points to the address of the integer variable from above.
    8. Declare and intialize a double pointer that points to the address of the double variable from above.
    9. 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.
  • Output the pointer names along with the values of the 3 variables by dereferencing the pointer.
    • 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.
  • Use the pointers to modify each of the variables by adding 4.
    • To use a pointer to modify the variable, you must dereference the pointer.
    • In other words, dereferenced pointer = dereferenced pointer + 4
  • Output the pointer names along with the values of the 3 variables by dereferencing the pointer, again.
    • The output should show that the letter and numbers are increased by 4.
  • Output the variable names along with their values, again.
    • The output should show that the letter and numbers are increased by 4.
  • Use theExample Outputto format your output the same way.
  • 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.
    • Be sure to have read through the assignment policy for this class.
  • Example Output *** Please pay attention to your variable and pointer names. When printing the names of the variables and pointers, it should reflect the actual names of the variables and pointers you used in your program. ***
  • % 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

    blur-text-image

    Get Instant Access to Expert-Tailored Solutions

    See step-by-step solutions with expert insights and AI powered tools for academic success

    Step: 2

    blur-text-image

    Step: 3

    blur-text-image

    Ace Your Homework with AI

    Get the answers you need in no time with our AI-driven, step-by-step assistance

    Get Started

    Recommended Textbook for

    Introduction to Wireless and Mobile Systems

    Authors: Dharma P. Agrawal, Qing An Zeng

    4th edition

    1305087135, 978-1305087132, 9781305259621, 1305259629, 9781305537910 , 978-130508713

    More Books

    Students also viewed these Programming questions

    Question

    6 Cite five ways to develop coherent paragraphs

    Answered: 1 week ago

    Question

    8. What are the steps in the process for organizing messages?

    Answered: 1 week ago