informaticage

Random *void explicit example

May 15th, 2021
716
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <time.h>
  4.  
  5. typedef void *Item;
  6. Item random_num() {
  7.   int* p_numero = (int*)malloc(sizeof(int));
  8.   srand(time(NULL));
  9.   *p_numero = rand() % 10 + 1;
  10.   return (Item)p_numero;
  11. }
  12.  
  13. int main(void) {
  14.   printf("Num: %d", *((int *)random_num()));
  15.   return 0;
  16. }
RAW Paste Data