Thread: Two easy questions about pointers

  1. #1
    Registered User
    Join Date
    May 2017
    Posts
    101

    Two easy questions about pointers

    I have read about pointers but still I have some questions related to them:

    1) In the following example, we have a function with a pointer:

    int function(char *string, char ch)

    I fail to understand * and what's the purpose of that.

    2) In this example:


    for (int i=4; i>=0; i--) {
    printf("%p ", (p+i));
    printf("%d ", *(p+i));


    What is the purpose of putting a parenthesis? why is needed?

    Thank you in advance.

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    1. Perhaps these links might help: Basic Functions, Part II

    2. Did you put the statements into a small program and run it to see the output?

    Did you follow the links from the link I provided in my last post in your other topic to the pointer tutorial?

    Jim

  3. #3
    Registered User
    Join Date
    Apr 2017
    Location
    Iran
    Posts
    138
    Quote Originally Posted by JorgeChemE View Post
    I have read about pointers but still I have some questions related to them:

    1) In the following example, we have a function with a pointer:

    int function(char *string, char ch)

    I fail to understand * and what's the purpose of that.
    Here "string" is a pointer to char. You may need to read a reliable book on C. Such things are described in detail there.

    2) In this example:


    for (int i=4; i>=0; i--) {
    printf("%p ", (p+i));
    printf("%d ", *(p+i));


    What is the purpose of putting a parenthesis? why is needed?

    Thank you in advance.
    Look up operator precedence.
    *(p+i) is not same as (*p+i).

    C Operator Precedence Table

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Couple of easy questions
    By jim_0 in forum C++ Programming
    Replies: 4
    Last Post: 03-11-2014, 02:42 PM
  2. Understanding Pointers - Easy Questions.
    By Kurtanius21 in forum C Programming
    Replies: 3
    Last Post: 11-14-2012, 04:27 PM
  3. Two Easy Questions
    By CougarElite in forum C++ Programming
    Replies: 5
    Last Post: 03-28-2005, 09:58 PM
  4. two easy questions
    By ... in forum Windows Programming
    Replies: 12
    Last Post: 03-27-2003, 09:00 AM
  5. A few easy questions
    By pdstatha in forum C Programming
    Replies: 3
    Last Post: 03-29-2002, 10:41 AM

Tags for this Thread