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

preview_player
Показать описание

Use my code JKL10 to get 10% off on GATE subscription

Dear GATE 2022 participant,
Here's a chance to win exciting prizes upto 10x of your enrolment fee from a pool of ₹ 1 crore. Fill this form to register for Unacademy Unbeatables - GATE 2022 Rankers Reward Program.

Connect & Contact Me:

See Complete Playlists:
Рекомендации по теме
Комментарии
Автор

Difference between Malloc and Calloc function
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

_AHMATSENOUSSI
Автор

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

divyprakashpandey
Автор

Assignment one:

#include<stdio.h>
#include<stdlib.h>

int main (void)
{
int n, i, j, *ptr1;
float num, *ptr2;

printf("\nEnter number of blocks: ");
scanf("%d", &n);

ptr1=(int *)calloc(n, sizeof(int));
if(ptr1==NULL)
{
printf("Cannot allocate memory\n");
exit(1);
}

printf("Enter values for calloc: ");
for(i=0;i<n;i++)
{
scanf("%d", (ptr1 + i));
}

printf("Values of calloc are: \n");
for(i=0;i<n;i++)
{
printf("%d\t", *(ptr1 + i));
}
printf("\n");

free(ptr1);

printf("\nEnter number of float values: ");
scanf("%f", &num);

ptr2=(float *)malloc(num * sizeof(float));
if(ptr2==NULL)
{
printf("Did not allocate memory\n");
exit(1);
}

printf("Enter values for malloc: ");
for(j=0;j<num;j++)
{
scanf("%f", (ptr2 + j));
}

printf("Values of malloc are: ");
for(j=0;j<num;j++)
{
printf("%f\t", *(ptr2 + j));
}
printf("\n");

free(ptr2);

return 0;
}

abdulrahimjalloh
Автор

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

abdulrahimjalloh
Автор

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

devSackey
Автор

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

Skclubs
Автор

are so special....
thank you for being on YouTube for

learnwithme
Автор

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.

DevManuel-tx
Автор

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

jarpalasony
Автор

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

RiyaRoy-qitk
Автор

Gajab padhate ho mam 😍😍🥰 really very nice .

cheharmani
Автор

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

SakshiPatidar
Автор

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

VIDITSHRIMALI-lo
Автор

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

sheesh
Автор

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

_ayushmishra
Автор

Mam can you teach us competetive programing please

Sumit_
Автор

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

TanujGutta-rk
Автор

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, ,

navinvenkat
Автор

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

hareeshkumar
Автор

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

shAggarwal