Results 1 to 9 of 9
  1. #1
    JimTheGreat's Avatar
    Join Date
    Dec 2011
    Gender
    male
    Location
    USA
    Posts
    6,771
    Reputation
    125
    Thanks
    714
    My Mood
    Aggressive

    Exclamation Basics of Pointers

    #1.
    Code:
    #include <iostream>
    using namespace std;
    
    void IloveC++(double *firstpointer)
    {
         *firstpointer=9.95;
    }
    
    int main()
    {
         double x=5.342;
         *secondpointer=&x;
         IloveC++(secondpointer);
         cin.get()
         system("pause")
    }

    #2
    Code:
    #include <iostream>
    using namespace std;
    
    void *IloveC++(double firstpointer)
    {
         *firstpointer=9.95;
    }
    
    int main()
    {
         double x=5.342;
         *secondpointer=&x;
         IloveC++(secondpointer);
         cin.get()
         system("pause")
    }
    My question is, what's exactly the difference between shoving in a pointer (*) between "void" and "IloveC++" , and shoving in a pointer (*) between "double" and "firstpointer"?

    For a better understanding...

    What is the difference between this:
    Code:
    void *IloveC++(double firstpointer)
    ...and this?
    Code:
    void IloveC++(double *firstpointer)
    @giniyat101 specially ;p


    ---------- Post added at 07:05 PM ---------- Previous post was at 07:04 PM ----------

    EDIT: Okay forget the "system("pause")" thing I made a mistake lol.

  2. #2
    radnomguywfq3's Avatar
    Join Date
    Jan 2007
    Gender
    male
    Location
    J:\E\T\A\M\A\Y.exe
    Posts
    8,858
    Reputation
    381
    Thanks
    1,823
    My Mood
    Sad
    The general format of a function definition is this:

    Code:
    [decorations\calling-convention] [return data] [function name] ([argument 1], [argument 2], ... etc)
    The first bit can be ommited, the decorations & calling convention.

    void IloveCpp(double fValue);

    Defines a function that does not return anything (void) but takes a double value as an argument. The data in this situation is coppied over to the function. Generally, for small bits of data, this is acceptable. However, for larger structures you must use pointers or references.

    void* IloveCpp(double fValue);

    This function returns a pointer to any piece of data. A void pointer cannot be dereferenced. I.e you can not do this:

    Code:
    void* pReturn = IloveCpp(1.24);
    *pReturn = 25;
    void pointers typically are used to store arbitrary pointers or references to regions of memory that cannot be effectivley described with a structure. Nowadays, there are a lot of tricky hacks you can pull off with meta-programming to get a structure to accurately describe a region of memory, so try to use a structure pointer wherever possible.

    void ILoveCpp(double* pValue)

    Describes a function which returns nothing, but takes a pointer to a double value. In C++ you would just use a reference here (if you haven't learned about references don't worry about it.) In this case, a pointer to a value is passed reather than copying the actual value over in to the function's context (much more optimal.)

    It is also worth noting that you should not worry about returning structures. It varries with implementation by the comiler, but usually something like this:

    MyLargeStructure createStructure(const char* sName);

    turns in to something like this when optimized\implemented by the compiler:

    void createStructure(const char* sName, MyLargeStructure* pReturn);



    There are two types of tragedies in life. One is not getting what you want, the other is getting it.

    If you wake up at a different time in a different place, could you wake up as a different person?


  3. The Following User Says Thank You to radnomguywfq3 For This Useful Post:

    Hassan (07-16-2012)

  4. #3
    Jason's Avatar
    Join Date
    Apr 2010
    Gender
    male
    Location
    /dev/null
    Posts
    5,704
    Reputation
    918
    Thanks
    7,676
    My Mood
    Mellow
    Quote Originally Posted by Jetamay View Post
    The general format of a function definition is this:
    ... blah blah Imma baws blah blah
    Oh my god, can it be true? The great Jetafag is once again among us?

    Quote Originally Posted by Jeremy S. Anderson
    There are only two things to come out of Berkley, Unix and LSD,
    and I don’t think this is a coincidence
    You can win the rat race,
    But you're still nothing but a fucking RAT.


    ++Latest Projects++
    [Open Source] Injection Library
    Simple PE Cipher
    FilthyHooker - Simple Hooking Class
    CLR Injector - Inject .NET dlls with ease
    Simple Injection - An in-depth look
    MPGH's .NET SDK
    eJect - Simple Injector
    Basic PE Explorer (BETA)

  5. #4
    M-I-K-e's Avatar
    Join Date
    Jun 2012
    Gender
    male
    Posts
    8
    Reputation
    10
    Thanks
    4
    My Mood
    Amused
    Code:
    #include <iostream>
    using namespace std;
    
    void IloveC++(double *firstpointer)
    {
         *firstpointer=9.95;
    }
    
    int main()
    {
         double x=5.342;
         *secondpointer=&x;
         IloveC++(secondpointer);
         cin.get()
         system("pause")
    }
    Your function requires a pointer, but you do not necessarily have to create a pointer to pass an address to the function, although sometimes it is beneficial to do so.

    Example:
    Code:
    IloveC++(&x); // Here we are directly passing the address of 'x' to the function.
    Just a little bit of extra info I thought I would put in there for you.

  6. #5
    JimTheGreat's Avatar
    Join Date
    Dec 2011
    Gender
    male
    Location
    USA
    Posts
    6,771
    Reputation
    125
    Thanks
    714
    My Mood
    Aggressive
    Quote Originally Posted by Jetamay View Post
    void pointers typically are used to store arbitrary pointers or references to regions of memory that cannot be effectivley described with a structure. Nowadays, there are a lot of tricky hacks you can pull off with meta-programming to get a structure to accurately describe a region of memory, so try to use a structure pointer wherever possible.

    void ILoveCpp(double* pValue)

    Describes a function which returns nothing, but takes a pointer to a double value. In C++ you would just use a reference here (if you haven't learned about references don't worry about it.) In this case, a pointer to a value is passed reather than copying the actual value over in to the function's context (much more optimal.)

    It is also worth noting that you should not worry about returning structures. It varries with implementation by the comiler, but usually something like this:

    MyLargeStructure createStructure(const char* sName);

    turns in to something like this when optimized\implemented by the compiler:

    void createStructure(const char* sName, MyLargeStructure* pReturn);
    Well I do understand what "void" does and I just wanted to try something I haven't for my history of coding.
    So basically to say, if you shove in the pointer (*) in the function value, it only recognizes the exact value which it is pointing to, in this case, only 1, and if you shove it in at the function type, then it recognize every value that's within that function?
    Sorry I'm kind of confused here. Or maybe I should just move on to learning Classes and Struct variables.


    ---------- Post added at 12:32 PM ---------- Previous post was at 12:31 PM ----------

    Quote Originally Posted by M-I-K-e View Post
    Your function requires a pointer, but you do not necessarily have to create a pointer to pass an address to the function, although sometimes it is beneficial to do so.
    I know, I just wanted to practice some pointers and functions altogether.

  7. #6
    radnomguywfq3's Avatar
    Join Date
    Jan 2007
    Gender
    male
    Location
    J:\E\T\A\M\A\Y.exe
    Posts
    8,858
    Reputation
    381
    Thanks
    1,823
    My Mood
    Sad
    A float pointer holds the address of any given float variable.

    You can get the address of any accessible variable in memory by using the '&' token.

    I.e

    float myFloat = 2.0F

    then you can store the address of the float:

    float* pMyFloat = &myFloat;

    pMyFloat is a pointer to myFloat. It contains the address of myFloat in memory, not the value of myFloat.

    You can dereference a pointer by using the dereference operator (*)

    float myFloatsValue = *pMyFloat.

    It works the same way with function arguments.

    I don't fully understand your question, but I think this is what you're asking?



    There are two types of tragedies in life. One is not getting what you want, the other is getting it.

    If you wake up at a different time in a different place, could you wake up as a different person?


  8. The Following User Says Thank You to radnomguywfq3 For This Useful Post:

    Hassan (07-16-2012)

  9. #7
    JimTheGreat's Avatar
    Join Date
    Dec 2011
    Gender
    male
    Location
    USA
    Posts
    6,771
    Reputation
    125
    Thanks
    714
    My Mood
    Aggressive
    Quote Originally Posted by Jetamay View Post
    A float pointer holds the address of any given float variable.

    You can get the address of any accessible variable in memory by using the '&' token.

    I.e

    float myFloat = 2.0F

    then you can store the address of the float:

    float* pMyFloat = &myFloat;

    pMyFloat is a pointer to myFloat. It contains the address of myFloat in memory, not the value of myFloat.

    You can dereference a pointer by using the dereference operator (*)

    float myFloatsValue = *pMyFloat.

    It works the same way with function arguments.

    I don't fully understand your question, but I think this is what you're asking?
    :s I don't really understand this.
    Well I'm only on part 2 I have much more to go on pointers. I'll have a look at that first.
    For now, close @Hassan

  10. #8
    giniyat101's Avatar
    Join Date
    Sep 2011
    Gender
    male
    Location
    Not telling.
    Posts
    1,935
    Reputation
    130
    Thanks
    1,380
    My Mood
    Dead
    i didnt receive the mention :S
    may i didnt notice
    i think Jetamay already helped


     



    [img]https://i43.photobucke*****m/albums/e367/DeteSting/Steam-update.gif[/img]

  11. #9
    Hassan's Avatar
    Join Date
    May 2010
    Gender
    male
    Location
    System.Threading.Tasks
    Posts
    4,764
    Reputation
    495
    Thanks
    2,133
    My Mood
    Dead
    Marked Solved. Jetamay answered it pretty well.

Similar Threads

  1. [Release] Some Basic Offsets + Pointers
    By Swag in forum CrossFire Europe Hack Source Code
    Replies: 5
    Last Post: 01-08-2012, 02:00 AM
  2. [Release] Weapon Mgr, Player Pointer, Basic Player Info
    By Ryuesi in forum CrossFire Hack Coding / Programming / Source Code
    Replies: 12
    Last Post: 11-10-2011, 12:59 PM
  3. [Help] Inserting Pointers into Visual Basic 2010
    By zolferno in forum Visual Basic Programming
    Replies: 6
    Last Post: 08-14-2011, 06:40 AM
  4. Basic Signature
    By Chronologix in forum Tutorials
    Replies: 68
    Last Post: 09-25-2007, 12:33 AM
  5. Any Got Visual Basic Swim in air Pointer and No recoil and No spread??
    By Redbull in forum WarRock - International Hacks
    Replies: 0
    Last Post: 08-26-2007, 04:53 AM