Code questions.... Need Epic Help

This is a discussion on Code questions.... Need Epic Help within the C Programming forums, part of the General Programming Boards category; If anyone can assist I would be the most grateful person ever. I working with a programming book to learn ...

  1. #1
    Registered User
    Join Date
    Sep 2010
    Posts
    3

    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,
    ThatGuy

  2. #2
    Bored Programmer
    Join Date
    Jul 2009
    Location
    Tomball, TX
    Posts
    407
    What have you already coded, and why isn't it working?

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

  4. #4
    a guy with long hair Xupicor's Avatar
    Join Date
    Sep 2010
    Location
    Poland
    Posts
    103
    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
    Location
    Halesowen, England
    Posts
    30
    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:
    Code:
    int *i;
    This is because *i (read as 'the contents of the pointer i') is an integer.
    Setting a pointer is simple too:
    Code:
    int i, *j;
    j = &i;  /* j equals the address of i */
    You can manipulate the value held within a pointer location like:
    Code:
    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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,555
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

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, 11:40 AM
  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 Cprogramming.com
    Replies: 1
    Last Post: 08-14-2001, 07:22 AM

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