Will this work?

This is a discussion on Will this work? within the C Programming forums, part of the General Programming Boards category; First, let me point out that my grasp of pointers is thin at best! Will the following function do what ...

  1. #1
    Registered User
    Join Date
    Feb 2009
    Posts
    278

    Will this work?

    First, let me point out that my grasp of pointers is thin at best! Will the following function do what I want?

    Code:
    void Get_Timestamp(time_t *tOld_Timestamp, time_t *tNew_Timestamp) {
      *tOld_Timestamp = *tNew_Timestamp;
      *tNew_Timestamp = time(NULL);
    }
    If I was using ints I would know exactly what to do. After the function is over, I want tOld_Timestamp to point to the value that tNew_Timestamp used to point to, and I want tNew_Timestamp to point to whatever the result of the time() function call is.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,414
    Well, what happens here is that what tOld_Timestamp points to becomes a copy of what tNew_Timestamp points to, while what tNew_Timestamp points to is assigned a new value. It is probably what you intended, but technically the pointers continue to point to what they pointed to before the function was called.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Feb 2009
    Posts
    278
    The pointers still point to the same addresses, but the contents of those addresses has changed how I expect right?

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,414
    Quote Originally Posted by Bladactania
    The pointers still point to the same addresses, but the contents of those addresses has changed how I expect right?
    The contents of the objects at those addresses have changed, yes.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Registered User
    Join Date
    Feb 2009
    Posts
    278
    Thanks... Pointers give me a headache!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. strcmp returning 1...
    By Axel in forum C Programming
    Replies: 12
    Last Post: 09-08-2006, 07:48 PM
  2. getline() don't want to work anymore...
    By mikahell in forum C++ Programming
    Replies: 7
    Last Post: 07-31-2006, 10:50 AM
  3. Why don't the tutorials on this site work on my computer?
    By jsrig88 in forum C++ Programming
    Replies: 3
    Last Post: 05-15-2006, 10:39 PM
  4. fopen();
    By GanglyLamb in forum C Programming
    Replies: 8
    Last Post: 11-03-2002, 11:39 AM
  5. DLL __cdecl doesnt seem to work?
    By Xei in forum C++ Programming
    Replies: 6
    Last Post: 08-21-2002, 04:36 PM

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