-
Notifications
You must be signed in to change notification settings - Fork 0
/
Difference-between-malloc()-and-calloc()-in-C.php
420 lines (346 loc) · 11.7 KB
/
Difference-between-malloc()-and-calloc()-in-C.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
<!DOCTYPE html>
<html lang="en">
<head>
<title>Difference Between malloc() and calloc() in C.</title>
<meta charset="utf-8">
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="apple-touch-icon" href="apple-touch-icon.png">
<link rel="icon" href="../images/LearnDifferences_black_logo.png">
<link rel="stylesheet" href="css/bootstrap.min.css">
<link rel="stylesheet" href="css/mystyle.css">
<link rel="stylesheet" href="css/TableStyle.css">
<link rel="stylesheet" href="css/bootstrap-theme.min.css">
<link rel="stylesheet" href="css/main.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<script src="js/vendor/modernizr-2.8.3-respond-1.4.2.min.js"></script>
<style>
pre
{
width: 100%;
}
.navbar {
margin-bottom: 0;
border-radius: 0;
}
/* Set height of the grid so .sidenav can be 100% (adjust as needed) */
.row.content {height: 450px}
/* Set gray background color and 100% height */
.sidenav {
padding-top: 20px;
background-color: #f1f1f1;
height: 100%;
}
/* Set black background color, white text and some padding */
footer {
background-color: #555;
position: relative;
margin-top:-100px;
color: white;
clear: both;
}
/* On small screens, set height to 'auto' for sidenav and grid */
@media screen and (max-width: 767px) {
.sidenav {
height: auto;
padding: 15px;
}
.row.content {height:auto;}
}
hr {
display: block;
margin-top: 1.5em;
margin-bottom: 0.5em;
margin-left: auto;
margin-right: auto;
border-style: inset;
border-width: 2px;
}
.fa {
padding: 20px;
font-size: 30px;
width: 50px;
text-align: center;
text-decoration: none;
margin: 5px 2px;
border-radius: 5%;
}
.fa:hover {
opacity: 0.7;
}
.fa-facebook {
background: #3B5998;
color: white;
}
.fa-twitter {
background: #55ACEE;
color: white;
}
.fa-google {
background: #dd4b39;
color: white;
}
.fa-linkedin {
background: #007bb5;
color: white;
}
.fa-youtube {
background: #bb0000;
color: white;
}
.fa-instagram {
background: #125688;
color: white;
}
.fa-pinterest {
background: #cb2027;
color: white;
}
.fa-snapchat-ghost {
background: #fffc00;
color: white;
text-shadow: -1px 0 black, 0 1px black, 1px 0 black, 0 -1px black;
}
.fa-skype {
background: #00aff0;
color: white;
}
.fa-android {
background: #a4c639;
color: white;
}
.fa-dribbble {
background: #ea4c89;
color: white;
}
.fa-vimeo {
background: #45bbff;
color: white;
}
.fa-tumblr {
background: #2c4762;
color: white;
}
.fa-vine {
background: #00b489;
color: white;
}
.fa-foursquare {
background: #45bbff;
color: white;
}
.fa-stumbleupon {
background: #eb4924;
color: white;
}
.fa-flickr {
background: #f40083;
color: white;
}
.fa-yahoo {
background: #430297;
color: white;
}
.fa-soundcloud {
background: #ff5500;
color: white;
}
.fa-reddit {
background: #ff5700;
color: white;
}
.fa-rss {
background: #ff6600;
color: white;
}
p
{
font-family:Arial,garamond,sans-serif;
font-size:14px;
font-style:normal;
color: #2c4762;
}
</style>
</head>
<body bgcolor="#E6E6FA">
<div class="navbar navbar-inverse">
<header>
<div class="container-fluid text-center text-md-left">
<div class="col-sm-3">
<img width="18%" src="../images/LearnDifferences_black_logo.png" align="left"> <img width=" 82%" src="../images/Differencing_logo.png" align="right">
</div>
<div class="col-sm-6">
<h2><b>LearnDifferences.org</b></h2>
</div>
<div class="col-sm-3 ">
<div class="container-fluid">
<div class="row">
</div>
</div>
</div>
</div>
</header>
</div>
<nav class="navbar navbar-inverse">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#"><img width="30px" src="images/LearnDifference_white_logo.png"></a>
</div>
<div class="collapse navbar-collapse" id="myNavbar">
<ul class="nav navbar-nav">
<li ><a href="#">Home</a></li>
<li class="active"><a href="programming.php">Programming</a></li>
<li><a href="data_mining.php">Data Mining</a></li>
<li><a href="basic_scince.php">Basic Sciences</a></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li><a href="login.php"><span class="glyphicon glyphicon-log-in"></span> Login</a></li>
</ul>
</div>
</div>
</nav>
<div class="container-fluid text-center">
<div class="row content">
<div class="col-sm-3 sidenav">
<div class="list-group">
<a href="Difference-Between-Structure-Union-in-C.php" class="list-group-item">Structure and Union </a>
<a href="#" class="list-group-item active">malloc() and calloc()</a>
<a href="#" class="list-group-item">local and global var </a>
<a href="Difference-between-actual-formal-parameters-c.php" class="list-group-item">Formal and Actual Parameters</a>
<a href="#" class="list-group-item">getch()and getche()</a>
</div>
</div>
<div class="col-sm-7 text-left" style="background-color: #fff">
<div class=" row container-fluid text-center">
<h3>Difference Between malloc() and calloc() in C.</h3>
<p align="justify"> malloc() and calloc() functions are use to dynamically allocate memory.
In dynamic memory allocation, required memory are allocated at run time.
Dynamically allocated memory can be accessed any where and any time till the program terminated.
Dynamically allocated memory can be made free using free() function.
</p>
</div>
<div class=" row container-fluid">
<table>
<tr>
<th>S.N.</th><th>malloc()</th><th>calloc()</th>
</tr>
<tr><td>1</td><td><p>malloc() does not initializes the allocated memory.</p></td>
<td><p>calloc() initializes all bytes of allocated memory.</p></td>
</tr><tr><td>2</td><td><p>Default value of allocated memory is garbage value.</p></td>
<td><p>Default value of allocated memory is 0.</p></td>
</tr>
<tr><td>3</td><td><p>malloc() takes only one argument/input to allocate memory which is number of bytes memory to be allocated. </p></td>
<td><p>calloc () takes two arguments/inputs.First one is number of memory to be allocated and second one is the size of each memory.</p></td>
</tr>
<tr><td>4</td>
<td>
<p>
<pre>
Function prototype:
void *malloc(size_t n);
Example:
int *p;
p=(int*)malloc(5*sizeof(int));
/*it will allocate memory of
zide 5 time of size of int
data type.*/
</pre>
</p>
</td>
<td><p>
<pre>
Function prototype:
void *calloc(size_t n,size_t size);
Example:
int *p;
p=(int *)calloc(10, size(int));
/*it will allocate memory to
store array of 10 int values.*/
</pre></p></td></tr></table></div>
<div class=" row container-fluid text-right color1" ><h5><a href=""><i>By:</i> Mahendra Gupta</a></h5></div>
<div class=" row container-fluid text-left"><h4><i>References:</i></h4></div>
<div class=" row container-fluid"><ol><li><a href="https://en.wikipedia.org/wiki/C_dynamic_memory_allocation" target="_blank">https://en.wikipedia.org/wiki/C_dynamic_memory_allocation.</li><li><a href="https://www.dipmat.univpm.it/~demeio/public/the_c_programming_language_2.pdf" target="_blank">https://www.dipmat.univpm.it/~demeio/public/the_c_programming_language_2.pdf.</li><li><a href="http://cs-fundamentals.com/tech-interview/c/difference-between-malloc-and-calloc.php" target="_blank">http://cs-fundamentals.com/tech-interview/c/difference-between-malloc-and-calloc.php.</li></div></div>
<div class="col-sm-2 sidenav">
<div class="well">
<?php
$googleAd='<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<script>
(adsbygoogle = window.adsbygoogle || []).push({
google_ad_client: "ca-pub-1881482997365438",
enable_page_level_ads: true
});
</script>';
echo $googleAd;
?>
</div>
<div class="well">
</div>
</div>
</div>
<footer>
<!-- Footer Links -->
<div class="container-fluid text-center text-md-left">
<!-- Grid row -->
<div class="row">
<div class="col-md-1 mb-md-0 mb-3">
</div>
<div class="col-md-5 mt-md-0 mt-3 text-left">
<!-- Content -->
<br>
<h4 class="text-uppercase">Address</h5>
<p>Ward No. 9, Behind Tehshil, Bihari Colony<br> Anuppur, M.P-484224</p>
<h4 class="text-uppercase">Contacts;</h5>
<p>Email: [email protected]<br>Mobile: +919582429861<br>Contact Person: Mahendra Gupta</p>
</div>
<!-- Grid column -->
<hr >
<!-- Grid column -->
<div class="col-md-2 mb-md-0 mb-3">
<!-- Links -->
<ul class="list-unstyled">
<li>
<a href="https://www.google.com" class="fa fa-google"></a>
</li>
<li>
<a href="https://www.youtube.com" class="fa fa-youtube"></a>
</li>
</ul>
</div>
<div class="col-md-2 mb-md-0 mb-3">
<!-- Links -->
<ul class="list-unstyled">
<li>
<a href="https://www.facebook.com" class="fa fa-facebook"></a>
</li>
<li>
<a href="https://www.twitter.com" class="fa fa-twitter"></a>
</li>
</ul>
</div>
<div class="col-md-2 mb-md-0 mb-3">
<ul class="list-unstyled">
<li>
<a href="https://www.linkdin.com" class="fa fa-linkedin"></a>
</li>
<li>
<a href="https://www.instagram.com" class="fa fa-instagram"></a>
</li>
</ul>
</div>
<!-- Grid column -->
</div>
<!-- Grid row -->
</div>
<!-- Footer Links -->
<!-- Copyright -->
<div class="footer-copyright text-center py-3">© 2018 Copyright:
<a href="https://learndifferences.org"> LearnDifferences.org</a><br><br>
</div>
</footer>
</body>
</html>