advertisements
السلام عليكم ورحمة الله وبركاته
اليوم بإذن لله سنكمل سلسلة دورة تعلم لغة البرمجة سي
سنتكلم اليوم عن Pointers
وبالتحديد
Heap & stack
Memory Allocation
Static Allocation
Dynamic Allocation
malloc function
calloc function
realloc function
فيما يخص تمارين تطبيقية
ستكون بعد أن ننتهى من الدروس
تمرين تطبيقي :
#include "stdio.h" /* int main(int argc, char *argv[]) { int age = 0; // auto allocation // using the allocated Memory printf("Your Age ? "); scanf("%d", &age); printf("Age is %d \n", age); return 0; } // free the allocated Memory */ ///* int main(int argc, char *argv[]) { int* memoryallocated = NULL; memoryallocated = malloc(sizeof(int)); // allocate The Memory if (memoryallocated == NULL) { exit(0); } // using the memory printf("Your Age ? "); scanf("%d", memoryallocated); // we dont use &var to save input printf("Age is : %d \n", *memoryallocated); free(memoryallocated); // free the memory return 0; } //*/
تمرين تطبيقي :
#include "stdio.h" main() { int i; int * tab; //tab =malloc( 3 * sizeof(int)); tab = calloc(3,sizeof(int)); tab[0]=1; //tab[1]=1; tab[2]=1; tab=realloc(tab , 4 *sizeof(int) ); tab[3] = 5; for( i=0; i < 4; i++) { printf("%d\n",tab[i]); } free(tab); }
فديو الشرح :
في أمان الله وحفظه
0 commentaires :
Publier un commentaire