Disclaimer: This presentation is prepared by trainees of
baabtra as a part of mentoring program. This is not official
docu...
Week Target Achieved
1 30 23
2
3
Typing Speed
Jobs Applied
Week Company Designation Applied Date Current Status
1
2
3
Functions With Heap and Stack
Muhammed Ajmal IK
ajuik2008@gmail.com
www.facebook.com/username
twitter.com/username
in.link...
Overview
• Introduction
• Stack
• Heap
• Simple program
Introduction
• The memory a program uses is typically divided into
four different areas:
– The code area.
– The heap.
– Th...
Stack
• It is a particular portion of memory.
• It stores temporary variables created by each
function
• variables are all...
Stack contd..
Stack operation
• Push
• Pop
Heap
• Heap is the area of memory used for dynamic
memory allocation
• Stored in computer RAM just like the stack.
• Funct...
Heap contd.
• Variables on the heap must be destroyed manually.
• Function for memory deallocation
– Free()
Example for stack
Example for Heap
Find Average of n Number
#include<stdio.h>
#include<stdlib.h>
int main()
{
int *ptr,n,i;
float sum=0.0;
printf("Enter how ...
{
printf("Memory not allocated");
exit(0);
}
printf("enter element:");
for(i=0;i<n;++i)
{
scanf("%d",ptr+i);
sum=sum+ *(pt...
Thank you
If this presentation helped you, please visit our
page facebook.com/baabtra and like it.
Thanks in advance.
www.baabtra.co...
Contact Us
Emarald Mall (Big Bazar Building)
Mavoor Road, Kozhikode,
Kerala, India.
Ph: + 91 – 495 40 25 550
NC Complex, N...
Function with heap and stack
Upcoming SlideShare
Loading in …5
×

Function with heap and stack

229 views

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
229
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
10
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Function with heap and stack

  1. 1. Disclaimer: This presentation is prepared by trainees of baabtra as a part of mentoring program. This is not official document of baabtra –Mentoring Partner Baabtra-Mentoring Partner is the mentoring division of baabte System Technologies Pvt . Ltd
  2. 2. Week Target Achieved 1 30 23 2 3 Typing Speed
  3. 3. Jobs Applied Week Company Designation Applied Date Current Status 1 2 3
  4. 4. Functions With Heap and Stack Muhammed Ajmal IK ajuik2008@gmail.com www.facebook.com/username twitter.com/username in.linkedin.com/in/profilename 9745020951
  5. 5. Overview • Introduction • Stack • Heap • Simple program
  6. 6. Introduction • The memory a program uses is typically divided into four different areas: – The code area. – The heap. – The stack
  7. 7. Stack • It is a particular portion of memory. • It stores temporary variables created by each function • variables are allocated and freed automatically • the stack has size limits • stack is a last-in, first-out (LIFO) structure
  8. 8. Stack contd..
  9. 9. Stack operation • Push • Pop
  10. 10. Heap • Heap is the area of memory used for dynamic memory allocation • Stored in computer RAM just like the stack. • Function for memory allocation – Malloc() – Calloc() – Realloc()
  11. 11. Heap contd. • Variables on the heap must be destroyed manually. • Function for memory deallocation – Free()
  12. 12. Example for stack
  13. 13. Example for Heap
  14. 14. Find Average of n Number #include<stdio.h> #include<stdlib.h> int main() { int *ptr,n,i; float sum=0.0; printf("Enter how many Element you want to insert"); scanf("%d",&n); ptr=malloc(n*sizeof(int)); if(ptr==NULL)
  15. 15. { printf("Memory not allocated"); exit(0); } printf("enter element:"); for(i=0;i<n;++i) { scanf("%d",ptr+i); sum=sum+ *(ptr+i); } printf("n Average %f",(sum/n)); free(ptr); }
  16. 16. Thank you
  17. 17. If this presentation helped you, please visit our page facebook.com/baabtra and like it. Thanks in advance. www.baabtra.com | www.massbaab.com |www.baabte.com
  18. 18. Contact Us Emarald Mall (Big Bazar Building) Mavoor Road, Kozhikode, Kerala, India. Ph: + 91 – 495 40 25 550 NC Complex, Near Bus Stand Mukkam, Kozhikode, Kerala, India. Ph: + 91 – 495 40 25 550 Start up Village Eranakulam, Kerala, India. Email: info@baabtra.com IKK Road, East Hill, Kozhikode Kerala, India. Ph: + 91 – 495 30 63 624 NIT-TBI, NIT Campus, Kozhikode, Kerala, India.

×