SlideShare a Scribd company logo
1 of 20
Sreyachandran.v
Sreya.chandran31@gmail.com
www.facebook.com/sreya
twitter.com/username
in.linkedin.com/in/profilename
Stack and Heap
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
Stack
• Stack is a linear data structure in which a data item is
inserted and deleted at one record.
• A stack is called LIFO(Last In First Out) or
FILO(First In Last Out) structure.
• The first item added to a stack is the last item
removed from a stack.
• Compiler store the local variable inside the stack.
Push and Pop
• Writing a value to the stack is called push.
• Deleting a value from stack is called pop.
#include <stdio.h>
int hcf(int n1, int n2);
int main()
{
int n1, n2;
n1=24;
n2=16;
printf("H.C.F of %d and %d = %d", n1, n2, hcf(n1,n2));
return 0;
}
int hcf(int n1, int n2)
{
i f(n2!=0)
return hcf(n2, n1%n2);
else
return n1;
}
1.main()
n1=24
n2=16
2.hcf(24,16)
3.hcf(16,24%16)=hcf(16,8)
4.hcf(8,16%8)=hcf(8,0)n1=24
n2=16
hcf(24,16)
hcf(16,8)
hcf(8,0)
STACK
Representation of stack operation
Heap
• The heap is an area of memory reserved for dynamic
memory allocation.
• Dynamic allocation is a technique in which a program
can acquire storage space in main memory.
• In this method , the space for the program is allocated
from the free space during execution of the program.
• This free space is called Heap
Memory allocation functions
1. malloc()
This function is used to allocate memory space in
bytes to the variable of different data types.
Example: ptr = (int*)malloc(20);
Ptr=(data type*)malloc(given size);
#include<stdio.h>
#include<stdlib.h>
main()
{
int k,*p,j=0,sum=0;
printf("How many numbers:");
scanf("%d",&k);
p=(int*)malloc(k*sizeof(int));
printf("n enter the numbers");
while(j!=k)
{
scanf("%d", p+j);
j++;
}
j=0;
printf("sum: ");
while(j!=k)
{
sum=sum+*(p+j);
j++;
}
printf("%d",sum);
}
How many numbers:3
enter the numbers: 1 2 3
Sum: 6
2. calloc()
• This function is useful for allocating multiple blocks
of memory . It is declared with two arguments.
• It allocate 4 blocks of memory and each block
contain 2 bytes
• This function is usually used for allocating memory
for array and structure
Ptr =(int*)calloc(4,2);
#include<stdio.h>
#include<stdlib.h>
main()
{
int k,*p,j=0,sum=0;
printf("How many numbers:");
scanf("%d",&k);
p=(int*)calloc(k,2);
printf("nenter the numbers");
while(j!=k)
{
scanf("%d",p+j);
j++;
}
j=0;
printf("sum: ");
while(j!=k)
{
sum=sum+*(p+j);
j++;
}
printf("%d",sum);
}
How many numbers:3
enter the numbers: 1 2 3
Sum: 6
3.free()
• This function is used to release the memory allocated
by memory allocating functions.
• ptr is the pointer and free() releases the memory
occupied by the pointer variable.
free(ptr);
4.realloc()
• This function reallocate the main memory.
• This are made to shrink or enlarge the previously
allocated memory.
• It returns the address of the reallocated block.
• If the block cannot be reallocated returns NULL
#include<stdio.h>
#include<stdlib.h>
main()
{
char *str;
str=(char*)malloc(6);
str=("india");
printf("str=%s",str);
str=(char*)realloc(str,10);
str=("hindustan");
printf("nnew str=%s",str);
free(str);
}
str=india
new str=hindustan
Stack vs Heap
stack
• local variables only.
• limit on stack size.
• variables cannot be resized.
• space is managed efficiently
by CPU, memory will not
become fragmented .
heap
• variables can be accessed
globally .
• no limit on memory size.
• variables can be resized
using realloc() .
• no guarantee on efficient use
of space.
Want to learn more about programming or Looking to become a good programmer?
Are you wasting time on searching so many contents online?
Do you want to learn things quickly?
Tired of spending huge amount of money to become a Software professional?
Do an online course
@ baabtra.com
We put industry standards to practice. Our structured, activity based courses are so designed
to make a quick, good software professional out of anybody who holds a passion for coding.
Follow us @ twitter.com/baabtra
Like us @ facebook.com/baabtra
Subscribe to us @ youtube.com/baabtra
Become a follower @ slideshare.net/BaabtraMentoringPartner
Connect to us @ in.linkedin.com/in/baabtra
Give a feedback @ massbaab.com/baabtra
Thanks in advance
www.baabtra.com | www.massbaab.com |www.baabte.com
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
Cafit Square,
Hilite Business Park,
Near Pantheerankavu,
Kozhikode
Start up Village
Eranakulam,
Kerala, India.
Email: info@baabtra.com
Contact Us

More Related Content

Viewers also liked (20)

Open Power Template 2 presentation
Open Power Template 2 presentationOpen Power Template 2 presentation
Open Power Template 2 presentation
 
Xml
XmlXml
Xml
 
What is xml
What is xmlWhat is xml
What is xml
 
Xml
XmlXml
Xml
 
XML Training Presentation
XML Training PresentationXML Training Presentation
XML Training Presentation
 
Xml intro1
Xml intro1Xml intro1
Xml intro1
 
XML and Databases
XML and DatabasesXML and Databases
XML and Databases
 
Intro to JSON
Intro to JSONIntro to JSON
Intro to JSON
 
XML 101 presentation by Bill Kasdorf of Apex
XML 101 presentation by Bill Kasdorf of ApexXML 101 presentation by Bill Kasdorf of Apex
XML 101 presentation by Bill Kasdorf of Apex
 
Chapter 5 transactions and dcl statements
Chapter 5  transactions and dcl statementsChapter 5  transactions and dcl statements
Chapter 5 transactions and dcl statements
 
Jvm
JvmJvm
Jvm
 
Field Service Forum 2016
Field Service Forum 2016Field Service Forum 2016
Field Service Forum 2016
 
I-Gaming Forum 2015 Post Event Report
I-Gaming Forum 2015 Post Event ReportI-Gaming Forum 2015 Post Event Report
I-Gaming Forum 2015 Post Event Report
 
Claas diagram
Claas diagramClaas diagram
Claas diagram
 
Cpu and execution of instruction.
Cpu and execution of instruction.Cpu and execution of instruction.
Cpu and execution of instruction.
 
Meet Nordic IT Security Advisory board, David Jacoby
Meet Nordic IT Security Advisory board, David JacobyMeet Nordic IT Security Advisory board, David Jacoby
Meet Nordic IT Security Advisory board, David Jacoby
 
Exeption handling
Exeption handlingExeption handling
Exeption handling
 
Database normalisation
Database normalisationDatabase normalisation
Database normalisation
 
TOP5 facts about Mobile Payments
TOP5 facts about Mobile PaymentsTOP5 facts about Mobile Payments
TOP5 facts about Mobile Payments
 
OOP in java
OOP in javaOOP in java
OOP in java
 

Similar to Functions using stack and heap

Similar to Functions using stack and heap (20)

Introduction to c part -3
Introduction to c   part -3Introduction to c   part -3
Introduction to c part -3
 
Stack and heap
Stack and heapStack and heap
Stack and heap
 
Lec-1c.pdf
Lec-1c.pdfLec-1c.pdf
Lec-1c.pdf
 
Scope of variables
Scope of variablesScope of variables
Scope of variables
 
Functions with heap and stack
Functions with heap and stackFunctions with heap and stack
Functions with heap and stack
 
Leniar datastructure
Leniar datastructureLeniar datastructure
Leniar datastructure
 
Functions with heap and stack
Functions with heap and stackFunctions with heap and stack
Functions with heap and stack
 
dynamic-allocation.pdf
dynamic-allocation.pdfdynamic-allocation.pdf
dynamic-allocation.pdf
 
web programming UNIT VIII python by Bhavsingh Maloth
web programming UNIT VIII python by Bhavsingh Malothweb programming UNIT VIII python by Bhavsingh Maloth
web programming UNIT VIII python by Bhavsingh Maloth
 
Python ml
Python mlPython ml
Python ml
 
Move from C to Go
Move from C to GoMove from C to Go
Move from C to Go
 
L7 pointers
L7 pointersL7 pointers
L7 pointers
 
prakash ppt (2).pdf
prakash ppt (2).pdfprakash ppt (2).pdf
prakash ppt (2).pdf
 
Dynamic memory allocation
Dynamic memory allocationDynamic memory allocation
Dynamic memory allocation
 
TransmogrifAI - Automate Machine Learning Workflow with the power of Scala an...
TransmogrifAI - Automate Machine Learning Workflow with the power of Scala an...TransmogrifAI - Automate Machine Learning Workflow with the power of Scala an...
TransmogrifAI - Automate Machine Learning Workflow with the power of Scala an...
 
16 dynamic-memory-allocation
16 dynamic-memory-allocation16 dynamic-memory-allocation
16 dynamic-memory-allocation
 
Rpg Pointers And User Space
Rpg Pointers And User SpaceRpg Pointers And User Space
Rpg Pointers And User Space
 
Anagha
AnaghaAnagha
Anagha
 
JCConf 2020 - New Java Features Released in 2020
JCConf 2020 - New Java Features Released in 2020JCConf 2020 - New Java Features Released in 2020
JCConf 2020 - New Java Features Released in 2020
 
C
CC
C
 

More from baabtra.com - No. 1 supplier of quality freshers

More from baabtra.com - No. 1 supplier of quality freshers (20)

Agile methodology and scrum development
Agile methodology and scrum developmentAgile methodology and scrum development
Agile methodology and scrum development
 
Best coding practices
Best coding practicesBest coding practices
Best coding practices
 
Core java - baabtra
Core java - baabtraCore java - baabtra
Core java - baabtra
 
Acquiring new skills what you should know
Acquiring new skills   what you should knowAcquiring new skills   what you should know
Acquiring new skills what you should know
 
Baabtra.com programming at school
Baabtra.com programming at schoolBaabtra.com programming at school
Baabtra.com programming at school
 
99LMS for Enterprises - LMS that you will love
99LMS for Enterprises - LMS that you will love 99LMS for Enterprises - LMS that you will love
99LMS for Enterprises - LMS that you will love
 
Php sessions & cookies
Php sessions & cookiesPhp sessions & cookies
Php sessions & cookies
 
Php database connectivity
Php database connectivityPhp database connectivity
Php database connectivity
 
Chapter 6 database normalisation
Chapter 6  database normalisationChapter 6  database normalisation
Chapter 6 database normalisation
 
Chapter 4 functions, views, indexing
Chapter 4  functions, views, indexingChapter 4  functions, views, indexing
Chapter 4 functions, views, indexing
 
Chapter 3 stored procedures
Chapter 3 stored proceduresChapter 3 stored procedures
Chapter 3 stored procedures
 
Chapter 2 grouping,scalar and aggergate functions,joins inner join,outer join
Chapter 2  grouping,scalar and aggergate functions,joins   inner join,outer joinChapter 2  grouping,scalar and aggergate functions,joins   inner join,outer join
Chapter 2 grouping,scalar and aggergate functions,joins inner join,outer join
 
Chapter 1 introduction to sql server
Chapter 1 introduction to sql serverChapter 1 introduction to sql server
Chapter 1 introduction to sql server
 
Chapter 1 introduction to sql server
Chapter 1 introduction to sql serverChapter 1 introduction to sql server
Chapter 1 introduction to sql server
 
Microsoft holo lens
Microsoft holo lensMicrosoft holo lens
Microsoft holo lens
 
Blue brain
Blue brainBlue brain
Blue brain
 
5g
5g5g
5g
 
Aptitude skills baabtra
Aptitude skills baabtraAptitude skills baabtra
Aptitude skills baabtra
 
Gd baabtra
Gd baabtraGd baabtra
Gd baabtra
 
Baabtra soft skills
Baabtra soft skillsBaabtra soft skills
Baabtra soft skills
 

Recently uploaded

SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piececharlottematthew16
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 

Recently uploaded (20)

SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Story boards and shot lists for my a level piece
Story boards and shot lists for my a level pieceStory boards and shot lists for my a level piece
Story boards and shot lists for my a level piece
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 

Functions using stack and heap

  • 1.
  • 3. 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
  • 4. Stack • Stack is a linear data structure in which a data item is inserted and deleted at one record. • A stack is called LIFO(Last In First Out) or FILO(First In Last Out) structure. • The first item added to a stack is the last item removed from a stack. • Compiler store the local variable inside the stack.
  • 5. Push and Pop • Writing a value to the stack is called push. • Deleting a value from stack is called pop.
  • 6. #include <stdio.h> int hcf(int n1, int n2); int main() { int n1, n2; n1=24; n2=16; printf("H.C.F of %d and %d = %d", n1, n2, hcf(n1,n2)); return 0; } int hcf(int n1, int n2) { i f(n2!=0) return hcf(n2, n1%n2); else return n1; }
  • 8. Heap • The heap is an area of memory reserved for dynamic memory allocation. • Dynamic allocation is a technique in which a program can acquire storage space in main memory. • In this method , the space for the program is allocated from the free space during execution of the program. • This free space is called Heap
  • 9. Memory allocation functions 1. malloc() This function is used to allocate memory space in bytes to the variable of different data types. Example: ptr = (int*)malloc(20); Ptr=(data type*)malloc(given size);
  • 10. #include<stdio.h> #include<stdlib.h> main() { int k,*p,j=0,sum=0; printf("How many numbers:"); scanf("%d",&k); p=(int*)malloc(k*sizeof(int)); printf("n enter the numbers"); while(j!=k) { scanf("%d", p+j); j++; } j=0; printf("sum: "); while(j!=k) { sum=sum+*(p+j); j++; } printf("%d",sum); } How many numbers:3 enter the numbers: 1 2 3 Sum: 6
  • 11. 2. calloc() • This function is useful for allocating multiple blocks of memory . It is declared with two arguments. • It allocate 4 blocks of memory and each block contain 2 bytes • This function is usually used for allocating memory for array and structure Ptr =(int*)calloc(4,2);
  • 12. #include<stdio.h> #include<stdlib.h> main() { int k,*p,j=0,sum=0; printf("How many numbers:"); scanf("%d",&k); p=(int*)calloc(k,2); printf("nenter the numbers"); while(j!=k) { scanf("%d",p+j); j++; } j=0; printf("sum: "); while(j!=k) { sum=sum+*(p+j); j++; } printf("%d",sum); } How many numbers:3 enter the numbers: 1 2 3 Sum: 6
  • 13. 3.free() • This function is used to release the memory allocated by memory allocating functions. • ptr is the pointer and free() releases the memory occupied by the pointer variable. free(ptr);
  • 14. 4.realloc() • This function reallocate the main memory. • This are made to shrink or enlarge the previously allocated memory. • It returns the address of the reallocated block. • If the block cannot be reallocated returns NULL
  • 16. Stack vs Heap stack • local variables only. • limit on stack size. • variables cannot be resized. • space is managed efficiently by CPU, memory will not become fragmented . heap • variables can be accessed globally . • no limit on memory size. • variables can be resized using realloc() . • no guarantee on efficient use of space.
  • 17.
  • 18. Want to learn more about programming or Looking to become a good programmer? Are you wasting time on searching so many contents online? Do you want to learn things quickly? Tired of spending huge amount of money to become a Software professional? Do an online course @ baabtra.com We put industry standards to practice. Our structured, activity based courses are so designed to make a quick, good software professional out of anybody who holds a passion for coding.
  • 19. Follow us @ twitter.com/baabtra Like us @ facebook.com/baabtra Subscribe to us @ youtube.com/baabtra Become a follower @ slideshare.net/BaabtraMentoringPartner Connect to us @ in.linkedin.com/in/baabtra Give a feedback @ massbaab.com/baabtra Thanks in advance www.baabtra.com | www.massbaab.com |www.baabte.com
  • 20. 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 Cafit Square, Hilite Business Park, Near Pantheerankavu, Kozhikode Start up Village Eranakulam, Kerala, India. Email: info@baabtra.com Contact Us