function with heap and stack

19

Click here to load reader

Upload: baabtracom-no-1-supplier-of-quality-freshers

Post on 24-Jun-2015

102 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Function with heap and stack
Page 2: Function with heap and stack

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

Page 3: Function with heap and stack

Week Target Achieved

1 30 23

2

3

Typing Speed

Page 4: Function with heap and stack

Jobs Applied

Week Company Designation Applied Date Current Status

1

2

3

Page 5: Function with heap and stack

Functions With Heap and Stack

Muhammed Ajmal IK [email protected] www.facebook.com/username twitter.com/username in.linkedin.com/in/profilename 9745020951

Page 6: Function with heap and stack

Overview

• Introduction

• Stack

• Heap

• Simple program

Page 7: Function with heap and stack

Introduction

• The memory a program uses is typically divided into

four different areas:

– The code area.

– The heap.

– The stack

Page 8: Function with heap and stack

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

Page 9: Function with heap and stack

Stack contd..

Page 10: Function with heap and stack

Stack operation

• Push

• Pop

Page 11: Function with heap and stack

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()

Page 12: Function with heap and stack

Heap contd.

• Variables on the heap must be destroyed manually.

• Function for memory deallocation

– Free()

Page 13: Function with heap and stack

Example for stack

Page 14: Function with heap and stack

Example for Heap

Page 15: Function with heap and stack

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)

Page 16: Function with heap and stack

{ 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); }

Page 17: Function with heap and stack

Thank you

Page 18: Function with heap and stack

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

Page 19: Function with heap and stack

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: [email protected]

IKK Road, East Hill, Kozhikode Kerala, India. Ph: + 91 – 495 30 63 624

NIT-TBI, NIT Campus, Kozhikode, Kerala, India.