I need help with programs

This is a discussion on I need help with programs within the C++ Programming forums, part of the General Programming Boards category; This is what I am suppose to complete: For each of the following, write a single statement that performs the ...

  1. #1
    Registered User
    Join Date
    Nov 2002
    Posts
    2

    Unhappy I need help with programs

    This is what I am suppose to complete:

    For each of the following, write a single statement that performs the specified tasks. Assume the long integer variables value1 to value2 have been declared and that value1 has been initialized to 200000.

    a) Declare the variable longPtr to be a pointer to an object of type long.

    b) Assign the address of variable value1 to pointer variable longPtr

    c) Print the value of object pointed to by longPtr

    d) Assing the value of the object pointed to by longPtr to variable value2

    e) Print the value of value2

    f) Print the address of value1

    g) Print the address stored in longPtr.

    Below is what I came up with. I would appreciate any help tha you can offer.


    a.) int longPtr *value1[200000];

    b.) longPtr=&value1;

    c.) printf(longPtr=value1);

    d.) int longPtr *value2[1];

    e.) int printf = value2;

    f.) int printf(address of value1);

    g. ) int printf; (longPtr = address);

  2. #2
    Bios Raider biosninja's Avatar
    Join Date
    Jul 2002
    Location
    South Africa
    Posts
    765
    Homework?
    The knack of flying is learning to throw yourself at the ground and miss.

  3. #3
    Registered User
    Join Date
    Nov 2001
    Posts
    1,348
    Post a specific questions.

    Kuphryn

  4. #4
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    new?
    Code:
    1) long *longPtr; //declares a pointer to a long
    2) longPtr = &variable1; //assigns the address of (&) variable1 to longPtr
    3) std::cout << *longPtr; //prints the value pointed to by (*) longPtr
    4) variable2 = *longPtr; //assigns the value pointed to by (*) longPtr to variable2
    5) std::cout << variable2; //prints the value of variable2
    6) std::cout << &variable1; //prints the address of (&) variable1
    7) std::cout << longPtr; //prints the value of longPtr, which is the address of variable1 right now
    It's written in C++ (i.e. the std::cout's, but those are the c++ version of printf()), you might learn something
    P.S. this looks like C, but it's posted in the C++ forum.
    Last edited by Hunter2; 11-26-2002 at 01:25 PM.
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  5. #5
    Registered User
    Join Date
    Nov 2002
    Posts
    2

    Thumbs up Thanks for the help, actually the course I am taking is called C/C++

    I really appreciate your help.

  6. #6
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    Any day After all, you did try for yourself.
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Starting programs
    By Molokai in forum C Programming
    Replies: 1
    Last Post: 04-16-2009, 11:10 AM
  2. Recommend upgrade path for C programs
    By emanresu in forum C Programming
    Replies: 3
    Last Post: 11-22-2007, 07:32 AM
  3. POSIX/DOS programs?
    By nickname_changed in forum C++ Programming
    Replies: 1
    Last Post: 02-28-2003, 05:42 AM
  4. executing c++ programs on the web
    By gulti01 in forum C++ Programming
    Replies: 4
    Last Post: 08-12-2002, 04:12 AM
  5. Release MFC Programs & Dynamic MFC DLL :: MFC
    By kuphryn in forum Windows Programming
    Replies: 2
    Last Post: 05-18-2002, 07:42 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21