Advertisement
informaticage

ansi C memory examples

Oct 23rd, 2021
1,100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.62 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. int main () {
  6.     char** stringhe = (char**)malloc(sizeof(char*) * 10);
  7.  
  8.     for(int i = 0; i < 10; i++) {
  9.         stringhe[i] = (char*) malloc(sizeof(char) * 5);
  10.         memset(stringhe[i], 'a' + i, 5);
  11.         stringhe[i][4] = '\0';
  12.     }
  13.  
  14.     for(int i = 0; i < 10; i++) {
  15.         printf("%s\n", stringhe[i]);
  16.     }
  17.  
  18.     // int* dati = (int*)malloc(sizeof(int) * 1000);
  19.     // memset(dati, 0, 1000);
  20.     // // 00000011 00000011 00000011 00000011
  21.     // for(int i = 0; i < 1000; i++) {
  22.     //     printf("%d ", dati[i]);
  23.     // }
  24.     return 0;
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement