Thread: C pointers

  1. #1
    Registered User
    Join Date
    Nov 2015
    Posts
    7

    Angry C pointers

    I would like to ask about some expressions in c pointers


    This is the example I will ask about with the output
    http://xm.tl/a1084766

    I want to understand each line meaning and why it print this output in each line

    I'll be thankful for anyone help me because I'm very confused.

  2. #2
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,738
    If you know this, you can explain the lines easily:
    Indirection and Address-of Operators
    Devoted my life to programming...

  3. #3
    Registered User
    Join Date
    Oct 2011
    Location
    Surin, Thailand
    Posts
    41
    In the code snippet you linked to, the variable named "i" is holding the integer number 3 in memory. Where that number is, for the most part, ain't important. Just assume it's located deep within the bowels of your computer. The variable "j" is holding yet another number someplace else in memory, except this time it's defined as an address-holder, a pointer to an integer. In this case, it is pointing to where the value of i is residing. Repeat the process for variable "k". It's simply another variable holding a number which this time, points to a pointer, a **.

    Those little stars preceding the variable name within the definitions specify the variable's type. Those same stars also fetch what's inside the spot in memory that the variable is pointing to. The more stars you have before it, the deeper it digs. The ampersand symbol "&" simply returns the address of the variable itself.

    I'll write-up an example using mailboxes if this isn't clear enough.
    Last edited by Todd_65536; 11-22-2015 at 08:15 AM.

  4. #4
    Registered User
    Join Date
    Nov 2015
    Posts
    7
    Quote Originally Posted by GReaper View Post
    If you know this, you can explain the lines easily:
    Indirection and Address-of Operators

    It is very good book, I am working on it now, But there is another Question

    http://xm.tl/a1084922

    In this program, Why i dies when the control exit the function?

    Thank you

  5. #5
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,738
    Quote Originally Posted by The coder View Post
    In this program, Why i dies when the control exit the function?
    Because you return the address of a temporary variable, which "doesn't exist" after the function ends.
    Devoted my life to programming...

  6. #6
    Registered User
    Join Date
    Nov 2015
    Posts
    7
    Quote Originally Posted by GReaper View Post
    Because you return the address of a temporary variable, which "doesn't exist" after the function ends.
    Thank you very much GReaper

    The last Question and I'll be thankful <3

    http://xm.tl/a1084993

    Why this program did not print 7.0000 ? like c++

  7. #7
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,738
    "%f" expects a float or double, you give it an int. It doesn't know what to do with it.
    Devoted my life to programming...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 4
    Last Post: 08-29-2015, 01:15 PM
  2. Replies: 43
    Last Post: 05-23-2013, 03:01 PM
  3. size of struct with pointers and function pointers
    By sdsjohnny in forum C Programming
    Replies: 3
    Last Post: 07-02-2010, 05:19 AM
  4. Storing function pointers in generic pointers
    By Boxknife in forum C Programming
    Replies: 6
    Last Post: 08-01-2009, 01:33 PM
  5. Pointers to objects -- passing and returning pointers
    By 1veedo in forum C++ Programming
    Replies: 4
    Last Post: 04-04-2008, 11:42 AM