Skip to content

Instantly share code, notes, and snippets.

@travisperson
Created October 9, 2012 04:14
Show Gist options
  • Save travisperson/3856551 to your computer and use it in GitHub Desktop.
Save travisperson/3856551 to your computer and use it in GitHub Desktop.
Pointers
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main ()
{
int mynums[3];
int i =0;
/*
mynums[0] = 5;
mynums[1] = 6;
mynums[2] = 7;
*/
*(mynums + 0) = 5;
*(mynums + 1) = 6;
*(mynums + 2) = 7;
for ( i = 0; i< 3; i++ )
{
printf("%d\n", mynums[i]);
}
return 0;
}
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
void roll_dice (int * roll_1, int * roll_2)
{
*roll_1 = rand() % 6 + 1;
*roll_2 = rand() % 6 + 1;
}
int main ()
{
srand( time(NULL) );
int dice_roll_1 = 0;
int dice_roll_2 = 0;
printf("&dice_roll_1 = %d, &dice_roll_2 = %d\n", &dice_roll_1, &dice_roll_2);
roll_dice( &dice_roll_1, &dice_roll_2 );
printf( "%d, %d", dice_roll_1, dice_roll_2 );
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment