C_134 Dynamic Memory Allocation using calloc() | C Language Tutorials

Поделиться
HTML-код
  • Опубликовано: 14 дек 2024

Комментарии • 83

  • @_AHMATSENOUSSI
    @_AHMATSENOUSSI 2 года назад +52

    Difference between Malloc and Calloc function
    MALLOC CALLOC
    -Accept one argument only -Accept two argument
    -The allocated memory would be initialized With garbage value -The allocated memory would be initialized with 0.
    -Allocate single block of memory - Allocate multiple block of memory

  • @abdulrahimjalloh363
    @abdulrahimjalloh363 Год назад +18

    Assignment one:
    #include
    #include
    int main (void)
    {
    int n,i,j,*ptr1;
    float num,*ptr2;
    printf("
    Enter number of blocks: ");
    scanf("%d",&n);
    ptr1=(int *)calloc(n,sizeof(int));
    if(ptr1==NULL)
    {
    printf("Cannot allocate memory
    ");
    exit(1);
    }
    printf("Enter values for calloc: ");
    for(i=0;i

  • @divyprakashpandey4458
    @divyprakashpandey4458 Год назад +15

    This session's notes
    - Calloc() fxn
    - Calloc stands for Contiguous Allocation
    - Built-in function in stdlib.h
    - Its Function→Used to dynamically allocate multiple blocks of memory & each block is of same size
    - General Syntax↓
    - void* calloc(size_t no._of_blocks , size_t*size_of_each_block);
    - Malloc VS Calloc
    - In Calloc the blocks are initialized with 0 & in Malloc it is initialized with Garbage Value
    - In Malloc a Single block of memory is allotted, In Calloc for same memory smaller memory blocks are allotted [yes, it confuses me too

    • @naughty_nobitha
      @naughty_nobitha 7 месяцев назад

      bane xtral dengav ga

    • @rabbit-g3l
      @rabbit-g3l 15 дней назад

      I'm confused about the same thing too in the last point

  • @abdulrahimjalloh363
    @abdulrahimjalloh363 Год назад +4

    Assignment Two:
    1. callloc means "contiguous allocation"
    1. malloc means "memory allocation"
    2. calloc is generally used in array
    2. malloc is generally used in structure
    3. calloc takes two arguments
    3 malloc takes one argument
    4 calloc dynamically allocate multiple block of memory of the same size
    4. malloc allocate single block of memory
    5. by default calloc initialize with zero values
    5. by default malloc initialize with garbage values

  • @devSackey
    @devSackey Год назад +3

    Diifrence betweeen malloc() and calloc() functions
    Malloc()
    1. The allocated memory by default is initialised with garbage value
    2. Allocate a singly large block of memory
    3. The function has one parameter
    Calloc()
    1. The allocated memory by default is initialised with 0
    2. Allocate multiple block of memory
    3. The function has two parameters

  • @jony-s5m
    @jony-s5m 2 года назад +5

    I love your teaching skill ma'am

  • @learnwithme6937
    @learnwithme6937 2 года назад +4

    mam.....you are so special....
    thank you for being on RUclips for us.........😇😇😇

  • @Skclubs988
    @Skclubs988 2 года назад +2

    So lovely mam i watching your videos since one year i cleared 3rd year help the ur video❤

  • @cheharmani1303
    @cheharmani1303 2 года назад +1

    Gajab padhate ho mam 😍😍🥰 really very nice .

  • @jarpalasony6569
    @jarpalasony6569 2 года назад +5

    Mam could you please upload a video on malloc( ) with structures

  • @SakshiPatidar371
    @SakshiPatidar371 2 года назад +3

    Thanku mam
    Please start python also...
    Please mam
    Ur teaching way is awesome
    Please 🙏

  • @akaza70701
    @akaza70701 2 года назад +1

    The way you talk mam...❤️ It's just too much flashy

  • @DevManuel-t6x
    @DevManuel-t6x Год назад +1

    Thank you first of all for all you have been doing, you have made c programming easy to grasp.
    I have a question please, some c programmers have raised the argument of typecasting the return value of malloc.
    They say it is not really right can you please shed more light on that because from my little understanding of C I actually agree with your method of Typecasting.

  • @efx.6990
    @efx.6990 2 года назад +16

    First view mam😍♥️

  • @VIDITSHRIMALI-l8o
    @VIDITSHRIMALI-l8o Месяц назад

    lots of thanks and appreciation for the beautiful content just like your beautiful heart

  • @RiyaRoy-qi6tk
    @RiyaRoy-qi6tk 2 года назад +4

    mam why we use calloc ??
    what is need of calloc ??
    why we need multiple block of memory 😐🤔🤔

  • @TEJASPLAYZ
    @TEJASPLAYZ Год назад +1

    THANKS 👍👍

  • @18_ayushmishra62
    @18_ayushmishra62 2 года назад +1

    Inhi topic malloc calloc k liye to c dekhna chalu kiya aur 1 mahine se last topic khatm kar k baitha hu aur aj jak ispe video aya

  • @bhanuprasad9788
    @bhanuprasad9788 2 года назад +1

    Continue mam never stop

  • @Sumit_152
    @Sumit_152 2 года назад +5

    Mam can you teach us competetive programing please

  • @bathinibhargavaram7126
    @bathinibhargavaram7126 3 месяца назад

    Thank you so much mam🙏🤗..

  • @DaniyelTutorials
    @DaniyelTutorials 2 года назад

    Beautiful
    Lecture

  • @RahulYadav-hr7bx
    @RahulYadav-hr7bx 2 года назад +3

    Mam if possible make a separate video on STATIC variable ,,, because it is very confusing

    • @therash09
      @therash09 2 года назад +1

      static means that the variable (even local) remains for the lifetime of the program and is not destroyed. Its accessibility is limited to the scope where it is defined (like function or file), but its value is not reinitialized during any access after the first access since the variable remains preserved throughout the code lifetime.
      If you initialize a local variable x in a function as static int x=0, and then increment it by 1 in each call of this function, then your outputs after five function calls will be 1,2,3,4,5. This is because static x retains its value from the last function call and is not reinitialized to 0, since x is not destroyed at the end of every function call. If, however, you declare x as an auto variable by simply doing int x=0, and call the function five times, then your output will be 1,1,1,1,1. This is because the auto variable will be reinitialized to 0 in each function call, as it will have been destroyed at the end of the previous function call.
      So, static preserves the variable even after your function and its local auto variables have been popped out of stack since static variables are not stored on stack, and therefore remain till the end of the program, thereby retaining their value. So, they behave like global variables but with their accessibility limited to the function in which they are defined. You can expand this understanding to multiple files in a program too. It is good to define variables as static locally to limit their accessibility to the function or file of interest, instead of declaring them as global. Static will preserve the variable values the same way as global, but limit the variable accessibility, which is good!

  • @pobbathisuryanarayana3752
    @pobbathisuryanarayana3752 2 года назад +2

    Malloc with structures make a separate video mam

  • @hareeshkumar7570
    @hareeshkumar7570 2 года назад +4

    Mam I'm from Pakistan and I'm in 1st semester watching your lectures
    but it is in c language while we are learning c++ so getting some difficulty to understand. Would you please make some lectures on object oriented programming in c++ because we are to Confused in it

  • @premwagh9480
    @premwagh9480 2 года назад +1

    why i'm reminding to priya gill after watching ma'am😄😄

  • @SairamTheegala
    @SairamTheegala 2 года назад

    ur awesome 💯

  • @navinvenkat3404
    @navinvenkat3404 2 года назад +1

    while i code assignment which was given by mam there is some error while executing it can anybody post that assignment code which was given by mam pls,,

  • @1shAggarwal
    @1shAggarwal 2 года назад +3

    Kal paper hai, or poori c language ki theory , or sab aa rha hai, or ye topic ab dala😔

  • @meghanakuppala
    @meghanakuppala 2 года назад

    Very nice 🙂

  • @CodingKitchen
    @CodingKitchen 2 года назад

    Thank you

  • @asifshinwari1552
    @asifshinwari1552 2 года назад

    wow in the black cloths you look so pretty

  • @abhisheksahu7643
    @abhisheksahu7643 Год назад

    Mam ap vs code ka konsa verson use karti ho

  • @errorless7921
    @errorless7921 2 года назад

    Thanku very much mam

  • @A_M_A_N794
    @A_M_A_N794 2 года назад

    thanks a lot

  • @nikithaa.s683
    @nikithaa.s683 Год назад

    Can you please say why we don't use calloc fuction while dynamically allocating memory for structures

  • @TanujGutta-r3k
    @TanujGutta-r3k Месяц назад

    In malloc memory is allocated to single block whereas in calloc multiple blocks are allocated with same memory

  • @56vaibhavjadhav36
    @56vaibhavjadhav36 2 года назад

    Hii ma'am
    Data structure and algorithm series is completed or some videos are coming.......

  • @udaysinghrana5725
    @udaysinghrana5725 Год назад

    Assignment Question -
    #include
    #include
    void main()
    {
    int *ptr,n,i;
    printf("
    How many values for calloc:");
    scanf("%d",&n);
    ptr = (int*) calloc(n,sizeof(int));
    for(i=0;i

  • @abdulrahimjalloh363
    @abdulrahimjalloh363 Год назад

    Madam Jenny is Ada Lovelace 2 🥰

  • @chetnawadhwa4345
    @chetnawadhwa4345 2 года назад

    Thank you mam

  • @shubhamitaliya3561
    @shubhamitaliya3561 Год назад

    amazing

  • @surajkumarchaubey210
    @surajkumarchaubey210 Год назад

    Nice mam

  • @Vinayvarma_25
    @Vinayvarma_25 13 дней назад

    Mam but we can do this like
    Scanf("%d",&n);
    a[n];
    //instead of malloc mam

  • @trendingmonkey5759
    @trendingmonkey5759 2 года назад +1

    Please tell the syllabus for gate exam mam now I am studying 1st year and I don't know what are the syllabus please help me mam I am from poor family I need to crack gate

  • @basuhosur-nh4di
    @basuhosur-nh4di Год назад

    Why not coming the garbage value and zero value mam?

  • @Mohan-im5wr
    @Mohan-im5wr 15 дней назад

    😊😊

  • @sikiodi5212
    @sikiodi5212 2 года назад +1

    Mam. Pls upload a topic regarding operator overloading in c++

  • @Euphony_Pro
    @Euphony_Pro Год назад

    i getting 0 for malloc function also. it is not generating and random garbage values

  • @dhavalgondaliya8707
    @dhavalgondaliya8707 2 года назад

    C language me abhi kitana baki hai ?

  • @beautyofnature4757
    @beautyofnature4757 Год назад +1

    I love you

  • @souviklayek2581
    @souviklayek2581 Год назад +1

    #include
    #include
    int main (){
    int i,n,*ptr;float*current;

    printf("Enter the value of n
    ");
    scanf("%d",&n);
    ptr=(int*)malloc(sizeof(int));
    printf("Enter the values
    ");
    for(i=0;i

  • @ajaytiwari6286
    @ajaytiwari6286 2 года назад +1

    Mam please start java or c++with c

  • @nitishgarg657
    @nitishgarg657 2 года назад

    Mam how many lectures left

  • @YDK_Edits
    @YDK_Edits 2 года назад +1

    Mam...you are so #beautiful ..

  • @rphanidattu1515
    @rphanidattu1515 2 года назад

    ❤️

  • @keerthibindu2455
    @keerthibindu2455 2 года назад

    Mam can you right and show me imp points

  • @swamy56
    @swamy56 2 года назад

    Why calloc intialized with ZERO& where malloc as GARBAGE???

  • @eiji2.025
    @eiji2.025 2 года назад +3

    Mam Yogi Ji Jeet Gye

  • @ronycb7168
    @ronycb7168 3 месяца назад

    Looks like they ran out of names when it came to naming calloc...

  • @cbcearth5056
    @cbcearth5056 2 года назад +1

    Maddam will you choose better explaining

  • @ffdf2195
    @ffdf2195 2 года назад +1

    ttttttttoooooooooppppppp

  • @dipoyadav5665
    @dipoyadav5665 Год назад

    Write a program to multiply given to matrices of order (Mxn) and (PxQ) using pointer
    Mam makes this program video in c programming

  • @tejhimanshu
    @tejhimanshu Год назад

    #include
    #include
    void main()
    {
    int *ptr, n, m, i, sum = 0;
    float *ptr1, avg = 0, avg_sum = 0;
    printf("enter total no of values for calloc: ");
    scanf("%d", &n);
    ptr = (int *)calloc(n, sizeof(int));
    if (ptr == NULL)
    {
    printf("memory allocation failed...");
    }
    printf("enter values:
    ");
    for (i = 0; i < n; i++)
    {
    scanf("%d", (ptr + i));
    sum = sum + *(ptr + i);
    }
    printf("Sum = %d
    ", sum);
    free(ptr);
    printf("enter total no of value for malloc: ");
    scanf("%d", &n);
    ptr1 = (float *)malloc(n * sizeof(float));
    if (ptr1 == NULL)
    {
    printf("memory allocation failed...");
    }
    printf("enter values:
    ");
    for (i = 0; i < n; i++)
    {
    scanf("%f", (ptr1 + i));
    avg_sum = avg_sum + *(ptr1 + i);
    }
    avg = avg_sum / n;
    printf("Average = %.2f", avg);
    free(ptr1);
    }

  • @atifreza4607
    @atifreza4607 2 года назад

    in alloc also im getting 0 value im not getting garbage value in malloc
    #include
    #include
    // malloc is stands for memory allocation
    int main(){
    int n,*p,i;
    printf("Enter the no u want to insert
    ");
    scanf("%d",&n);
    p=(int *)malloc(n*sizeof(int));
    // printf("Enter the values
    ");
    // for(i=0;i

  • @Manpreet_saini696
    @Manpreet_saini696 Год назад

    // Online C compiler to run C program online
    #include
    // Online C compiler to run C program online
    #include
    #include
    #include
    void main()
    {
    int n,i,*ptr;
    printf("no of values:");
    scanf("%d",&n);
    ptr=(int*)calloc(n,sizeof(int));
    printf("values are:");
    for(i=0;i

    • @Tech_Gyan.21
      @Tech_Gyan.21 Год назад

      We can't use Integer pointer to store address of floating value.

  • @abdulrahimjalloh363
    @abdulrahimjalloh363 Год назад

    Thanks mam

  • @aparnamane4899
    @aparnamane4899 2 года назад

    Malloc with structures make a separate video mam plz