Created
October 9, 2012 04:14
-
-
Save travisperson/3856551 to your computer and use it in GitHub Desktop.
Pointers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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