Thread: Code questions.... Need Epic Help

  1. #1
    Registered User
    Join Date
    Sep 2010

    Code questions.... Need Epic Help

    If anyone can assist I would be the most grateful person ever. I working with a programming book to learn and I have reached a standstill in the area of arrays and pointers... Thank you sooo very much in advance. These are the questions that I am attempting to answer:

    For each of the following, write a single statement that performs the indicated task. Assume that long integer variables value1 and value2 have been defines and that value 1 has been initialized to 200000.
    a. Define the variable lPtr to be a pointer to an object of type long.
    b. Assign the address of variable value1 to pointer variable lPtr.
    c. Print the value of the object pointed to by lPtr.
    d. Assign the value of the object pointed to by lPtr to variable value2.
    e. Print the value of value2.
    f. Print the address of value1.
    g. Print the address stored in lptr. Is the value printed the same as the address of value1?
    Write a printf of scanf statement for each of the following:
    a. Print unsigned integer 40000 left justified in a 15-digit field with 8 digits.
    b. Read a hexadecimal value into variable hex.
    c. Print 200 with and without a sign.
    d. Print 100 in hexadecimal form preceded by 0x.
    e. Read characters into array s until the letter p is encountered.

    Thanks once again,

  2. #2
    Bored Programmer
    Join Date
    Jul 2009
    Tomball, TX
    What have you already coded, and why isn't it working?
    Virtual reality hello world in html and javascript.
    Viewable with dodocase, google cardboard, OR, and other compatible VR gear.

  3. #3
    Registered User
    Join Date
    Sep 2010
    I've coded a lot up to this point but just can grasp it.

  4. #4
    Nasal Demon Xupicor's Avatar
    Join Date
    Sep 2010
    Did you read about arrays and pointers before trying answering those questions? If you did and still don't get it, then try reading it again. Maybe search some online tutorial and read the part on pointers.

    Lesshardtofind didn't ask you about your previous experience, but about this particular case.

  5. #5
    Registered User
    Join Date
    Sep 2010
    Halesowen, England
    Simply put, there are only really two thing to remember when working with pointers

    & is 'the address of', the physical location in memory where something is stored.
    * is 'the contents of', the value of the variable held at a memory location.

    Making a pointer is done like:
    int *i;
    This is because *i (read as 'the contents of the pointer i') is an integer.
    Setting a pointer is simple too:
    int i, *j;
    j = &i;  /* j equals the address of i */
    You can manipulate the value held within a pointer location like:
    int i, *j;
    j = &i;  /* j equals the address of i */
    *j = 5; /* Set the contents of j (the value of i) to 5 */
    if (i == *j) { /* Always True, both equal 5 */ }
    Once you have mastered this, pointer become much easier...

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    Closed - see Please Please help
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C interview questions
    By natrajdreams in forum C Programming
    Replies: 7
    Last Post: 12-12-2010, 12:40 PM
  2. Replies: 22
    Last Post: 09-26-2009, 07:21 AM
  3. Replies: 23
    Last Post: 04-20-2009, 07:35 AM
  4. Problem : Threads WILL NOT DIE!!
    By hanhao in forum C++ Programming
    Replies: 2
    Last Post: 04-16-2004, 01:37 PM
  5. questions questions questions.....
    By mfc2themax in forum A Brief History of
    Replies: 1
    Last Post: 08-14-2001, 07:22 AM