Thread: Pointer of int

Results 1 to 10 of 10
  1. #1
    w4ssup's Avatar
    Join Date
    Apr 2011
    Gender
    male
    Posts
    1,523
    Reputation
    10
    Thanks
    497

    Pointer of int

    I'm having a stroke or some shit but i cant seem to get this working (it been a while since i deal with pointers).
    I have a function that takes in a int pointer
    Code:
    void getINPUTandClear(int * something)
    I declared my var
    Code:
    int day = -1;
    \\or
    int * day;
    *day= -1;
    and I'm trying to pass the point to the function by
    Code:
    getINPUTandClear(&day);
    \\or
    getINPUTandClear(*day);
    \\or 
    getINPUTandClear(day);
    but all of those wouldn;t work. What's am i doing wrong?

  2. #2
    Zaczero's Avatar
    Join Date
    Oct 2013
    Gender
    male
    Location
    localhost
    Posts
    3,288
    Reputation
    1517
    Thanks
    14,262
    My Mood
    Angelic
    idk much about c++ pointers but shouldn't it be:
    void getINPUTandClear(int & something)
    . . . malsignature.com . . .



    [ global rules ] [ scam report ] [ image title ] [ name change ] [ anime force ]
    [ league of legends marketplace rules ] [ battlefield marketplace rules ]

    "because everytime you post a picture of anime in here
    your virginity's time increases by 1 month"
    ~Smoke 2/18/2018


    Former Staff 09-29-2018
    Battlefield Minion 07-21-2018
    Premium Seller 03-04-2018
    Publicist 12-10-2017
    League of Legends Minion 05-31-2017
    Premium 02-05-2017
    Member 10-13-2013

  3. #3
    WasserEsser's Avatar
    Join Date
    Jul 2015
    Gender
    male
    Posts
    735
    Reputation
    174
    Thanks
    677
    My Mood
    Busy
    Use references wherever possible, use pointers only if you can't avoid them.

    Regardless, if you want to use pointers, this should work just fine:

    Code:
    void getINPUTandClear(int* something);
    
    int day = -1;
    
    getINPUTandClear(&day);
    or else if you declare day as a pointer:

    Code:
    void getINPUTandClear(int* something);
    
    int* day;
    *day = -1;
    
    getINPUTandClear(day);

  4. #4
    Hell_Demon's Avatar
    Join Date
    Mar 2008
    Gender
    male
    Location
    I love causing havoc
    Posts
    3,976
    Reputation
    343
    Thanks
    4,320
    My Mood
    Cheeky
    Quote Originally Posted by WasserEsser View Post

    or else if you declare day as a pointer:

    Code:
    void getINPUTandClear(int* something);
    
    int* day;
    *day = -1;
    
    getINPUTandClear(day);
    In both this and OPs example the day pointer is uninitialized.
    Ah we-a blaze the fyah, make it bun dem!

  5. #5
    WasserEsser's Avatar
    Join Date
    Jul 2015
    Gender
    male
    Posts
    735
    Reputation
    174
    Thanks
    677
    My Mood
    Busy
    Quote Originally Posted by Hell_Demon View Post
    In both this and OPs example the day pointer is uninitialized.
    Correct, overlooked that.

  6. #6
    Leave_Em_Leakin's Avatar
    Join Date
    Jun 2017
    Gender
    male
    Location
    @putty
    Posts
    82
    Reputation
    10
    Thanks
    8
    My Mood
    Mellow
    Quote Originally Posted by WasserEsser View Post
    Use references wherever possible, use pointers only if you can't avoid them.

    Regardless, if you want to use pointers, this should work just fine:

    Code:
    void getINPUTandClear(int* something);
    
    int day = -1;
    
    getINPUTandClear(&day);
    or else if you declare day as a pointer:

    Code:
    void getINPUTandClear(int* something);
    
    int* day;
    *day = -1;
    
    getINPUTandClear(day);
    The day pointer will need to be initialized to point to the variable that will be actually modified.

  7. #7
    WasserEsser's Avatar
    Join Date
    Jul 2015
    Gender
    male
    Posts
    735
    Reputation
    174
    Thanks
    677
    My Mood
    Busy
    Quote Originally Posted by Leave_Em_Leakin View Post
    The day pointer will need to be initialized to point to the variable that will be actually modified.
    Read the rest of the thread next time.

  8. #8
    Kappatos's Avatar
    Join Date
    Jun 2015
    Gender
    male
    Posts
    152
    Reputation
    44
    Thanks
    11
    My Mood
    Cool
    In C:

    (U should use prints to understand how things work.)

    Code:
    #include <stdio.h>
    
    double minmaxavg(double array[], int num, double *max,double *min);
    
    double minmaxavg(double array[], int num, double *max,double *min){
    	int i;
    	double sum =0;
    	for(i =0;i< num;i++){
    		if(array[i] > *max){
    			*max = array[i];
    		}
    		if(array[i] < *min){
    			*min = array[i];
    		}
    		sum +=array[i];
    	}
    	return sum;
    }
    
    void main(){
    	double sum;
    	double max =1;
    	double min =1;
    	double arr[] = {1,3,2,5,4,6,8,7,99,0};
    	//double *pArr;
    	double *pMax;
    	double *pMin;
    	//pArr = &arr;
    	pMax = &max;
    	pMin = &min;
    	sum =minmaxavg(arr,10,pMax,pMin);
    	printf("sum:%g min:%g max:%g",sum,min,max);
    }
    Last edited by Kappatos; 06-03-2017 at 06:59 PM.

  9. #9
    Leave_Em_Leakin's Avatar
    Join Date
    Jun 2017
    Gender
    male
    Location
    @putty
    Posts
    82
    Reputation
    10
    Thanks
    8
    My Mood
    Mellow
    Quote Originally Posted by WasserEsser View Post
    Read the rest of the thread next time.
    I must have overlooked that.

  10. #10
    vidsac's Avatar
    Join Date
    Jul 2017
    Gender
    male
    Posts
    42
    Reputation
    10
    Thanks
    5
    My Mood
    Stressed
    youtube com/watch?v=Fa6S8Pz924k

    glhf

Similar Threads

  1. Play Helbreath Int Free! Free Mol Pins!
    By Dave84311 in forum Helbreath Hacks & Cheats
    Replies: 95
    Last Post: 07-09-2011, 02:45 PM
  2. Hellbreath Int Error?
    By RebornAce in forum General
    Replies: 10
    Last Post: 03-06-2009, 09:04 PM
  3. Warrock INT weopons pack???
    By Coolman in forum WarRock - International Hacks
    Replies: 17
    Last Post: 05-26-2007, 09:41 AM
  4. Weapon Pointer TUTORIAL
    By Fortran in forum WarRock - International Hacks
    Replies: 120
    Last Post: 02-10-2007, 08:44 PM
  5. Int. Warrock Out
    By quin123 in forum WarRock - International Hacks
    Replies: 12
    Last Post: 05-24-2006, 12:29 AM