#include <stdlib.h>
void generateTwoRandomNums(int random1, int random2){
random1 = rand() % 50 + 1;
random2 = rand() % 50 + 1;
printf("New random1 in function = %d\n\n", random1);
printf("New random2 in function = %d\n\n", random2);
}
void pointerRandomNumbers(int* random1, int* random2){
*random1 = rand() % 50 + 1;
*random2 = rand() % 50 + 1;
printf("New random1 in pointer function = %d\n\n", *random1);
printf("New random2 in pointer function = %d\n\n", *random2);
}
void main(void){
int random1 = 0, random2 = 0;
generateTwoRandomNums(random1, random2);
printf("random1 = %d\n\n", random1);
printf("random2 = %d\n\n", random2);
random1 = 0, random2 = 0;
printf("Main Before Function Call\n\n");
printf("random1 = %d : random2 = %d\n\n", random1, random2);
pointerRandomNumbers(&random1, &random2);
printf("Main After Function Call\n\n");
printf("random1 = %d : random2 = %d\n\n", random1, random2);
}
댓글 없음:
댓글 쓰기