SlideShare ist ein Scribd-Unternehmen logo
1 von 14
Downloaden Sie, um offline zu lesen
POINTERS IN ‘C’
Prakash Khaire,Lecturer
B V Patel Inst. of BMC & IT, GopalVidyanagar
What is a variable?
Each variable must be defined before you can
●


use it inside your program.
Did you ask yourself why we have to declare
●


variables?
●First reason is         To allocate memory
●Second reason is        Instruct compiler how
                         to treat this memory
                         location ML? As int or
                         float...
What is a variable?
int main()            Three memory locations have
{                     been allocated.
     int x = 16;
     float y = 2.3;   ●The first memory location
     char z = 70;
.                     holds int value.
.
.                     ● The second memory
}                     location holds floating-point
                      number.

                      ●The last memory location
                      holds one byte integer.
What is a variable?
●A variable is a named memory location.
●Variables provide direct access to its memory
location.
●Can you understand what will happen when you
write:
             int x;
                             X     variable
       x = 44;
                          44    value

                         1638       address
Memory Addresses
Each Memory Location has an address ➔ each
●


variable has an address.
Memory address in 32-bit Machines is 32-bit
●


unsigned integer number.
How to get the address of a variable?
●


   &variable_name
int i=15;
●


printf(“%d
●              %u”,i,&i);
&i returns the address of i.
●
Pointer Variables
●   Ask yourself:
●What is an integer variable?
●What is a floating-point variable?

●What is a character variable?

●   Now, what is a pointer variable?
●   It is a variable that stores the memory address.
OR
●   It points to a storage locations of memory.
       OR
●   Pointers contain memory addresses as their values.
Declaring Pointer Variables
Like ordinary variables, pointer variable must be
●


declared before they are used.
Declaration form
●

●   datatype *pointer_variable;
●The * tells the compiler that this is pointer variable
●Pointer_variable will point to the given datatype

●   Declaration Style
●int* iptr;
●int *iptr;

●int *   iptr;
Example
●   int *iptr;
iptr is pointer variable of integer data type, it will store the
●

memory address of int data type.

●   float *fptr;
fptr is pointer variable of float data type, it will store memory
●

address of float data type.

●   char *cptr;
cptr is pointer variable of character data type, it will store
●

memory address of character data type.
Suspicious Pointer Conversion
When you assign a particular type of pointer
●


variable with address of different type, such type
of automatic type conversion is known as
suspicious type conversion.
In turbo c compiler it is not cause of any
●


compilation error but compiler will send one
warning message: suspicious pointer
conversion. So we should avoid suspicious
pointer conversion.
Generic Pointer
●void pointer in c is known as generic pointer. Literal
meaning of generic pointer is a pointer which can point
type of data.
●void *ptr;
●Here ptr is generic pointer.


NULL pointer is a pointer which is pointing to nothing.
●


NULL pointer points the base address of segment.
●int *ptr=(char *)0;
●float *ptr=(float *)0;

●char *ptr=(char *)0;

●double *ptr=(double *)0;

●char *ptr=’0’;

●int *ptr=NULL;


NULL is macro constant which has been defined in the
●


heard file stdio.h, alloc.h, mem.h, stddef.h and stdlib.h
as
wild pointer
A pointer in c which has not been initialized is
●


known as wild pointer.

●   Example:
void main()
{
      int *ptr;               Output: Any address
      printf("%un",ptr);     Garbage value
      printf("%d",*ptr);
}
Dangling pointer
●If any pointer is pointing the memory address of
any variable but after some time that variable
has been deleted from that memory location
while pointer is still pointing such memory
location. Such pointer is known as dangling
pointer and this problem is known as dangling
pointer problem.
Arithmetic Operations with
Pointer
Like ordinary variables, pointer variables can also be used as a
●


part of expression.
The following rules are applied when we perform arithmetic
●


operations on pointer variables.
●Address + Number= Address
●Address - Number= Address

●Address++ = Address

●Address-- = Address

●++Address = Address

●--Address = Address

●If we will add or subtract a number from an address result will also be an

address
Benefits of using pointer
●Efficient in handling arrays and data tables.
●Returns multiple values from a function.
●Use of pointer arrays to character strings results
in saving of data storage space in memory.
●Supports dynamic memory management.
●Can manipulate dynamic data structure.
●Increases execution speed and reduces
execution time

Weitere Àhnliche Inhalte

Was ist angesagt?

C programming - Pointers
C programming - PointersC programming - Pointers
C programming - PointersWingston
 
Presentation on pointer.
Presentation on pointer.Presentation on pointer.
Presentation on pointer.Md. Afif Al Mamun
 
Pointer in c++ part1
Pointer in c++ part1Pointer in c++ part1
Pointer in c++ part1Subhasis Nayak
 
Module 02 Pointers in C
Module 02 Pointers in CModule 02 Pointers in C
Module 02 Pointers in CTushar B Kute
 
Pointer in c program
Pointer in c programPointer in c program
Pointer in c programRumman Ansari
 
Pointers & References in C++
Pointers & References in C++Pointers & References in C++
Pointers & References in C++Ilio Catallo
 
detailed information about Pointers in c language
detailed information about Pointers in c languagedetailed information about Pointers in c language
detailed information about Pointers in c languagegourav kottawar
 
Pointer in C
Pointer in CPointer in C
Pointer in Cbipchulabmki
 
Introduction to pointers and memory management in C
Introduction to pointers and memory management in CIntroduction to pointers and memory management in C
Introduction to pointers and memory management in CUri Dekel
 
Pointers in c++
Pointers in c++Pointers in c++
Pointers in c++Vineeta Garg
 
Pointers (Pp Tminimizer)
Pointers (Pp Tminimizer)Pointers (Pp Tminimizer)
Pointers (Pp Tminimizer)tech4us
 
Pointer in c
Pointer in cPointer in c
Pointer in cImamul Kadir
 
Pointers in c++ by minal
Pointers in c++ by minalPointers in c++ by minal
Pointers in c++ by minalminal kumar soni
 
C programming - Pointer and DMA
C programming - Pointer and DMAC programming - Pointer and DMA
C programming - Pointer and DMAAchyut Devkota
 

Was ist angesagt? (20)

C programming - Pointers
C programming - PointersC programming - Pointers
C programming - Pointers
 
C pointer
C pointerC pointer
C pointer
 
C pointers
C pointersC pointers
C pointers
 
Pointers in C Programming
Pointers in C ProgrammingPointers in C Programming
Pointers in C Programming
 
Presentation on pointer.
Presentation on pointer.Presentation on pointer.
Presentation on pointer.
 
Pointer in c++ part1
Pointer in c++ part1Pointer in c++ part1
Pointer in c++ part1
 
Module 02 Pointers in C
Module 02 Pointers in CModule 02 Pointers in C
Module 02 Pointers in C
 
Pointer in c program
Pointer in c programPointer in c program
Pointer in c program
 
Pointers & References in C++
Pointers & References in C++Pointers & References in C++
Pointers & References in C++
 
detailed information about Pointers in c language
detailed information about Pointers in c languagedetailed information about Pointers in c language
detailed information about Pointers in c language
 
Pointer in C
Pointer in CPointer in C
Pointer in C
 
Introduction to pointers and memory management in C
Introduction to pointers and memory management in CIntroduction to pointers and memory management in C
Introduction to pointers and memory management in C
 
Ponters
PontersPonters
Ponters
 
Pointers in c++
Pointers in c++Pointers in c++
Pointers in c++
 
Pointers (Pp Tminimizer)
Pointers (Pp Tminimizer)Pointers (Pp Tminimizer)
Pointers (Pp Tminimizer)
 
Pointer in c
Pointer in cPointer in c
Pointer in c
 
Pointers in C
Pointers in CPointers in C
Pointers in C
 
Pointer in c
Pointer in cPointer in c
Pointer in c
 
Pointers in c++ by minal
Pointers in c++ by minalPointers in c++ by minal
Pointers in c++ by minal
 
C programming - Pointer and DMA
C programming - Pointer and DMAC programming - Pointer and DMA
C programming - Pointer and DMA
 

Andere mochten auch

Pointers in C
Pointers in CPointers in C
Pointers in Cguestdc3f16
 
Lecture 11 css_inculsion
Lecture 11 css_inculsionLecture 11 css_inculsion
Lecture 11 css_inculsioneShikshak
 
Introduction to computer_and_its_structure
Introduction to computer_and_its_structureIntroduction to computer_and_its_structure
Introduction to computer_and_its_structureeShikshak
 
Introduction to css
Introduction to cssIntroduction to css
Introduction to csseShikshak
 
Lecture 12 css_fonts
Lecture 12 css_fontsLecture 12 css_fonts
Lecture 12 css_fontseShikshak
 
Program development cyle
Program development cyleProgram development cyle
Program development cyleeShikshak
 
Computer programming programming_langugages
Computer programming programming_langugagesComputer programming programming_langugages
Computer programming programming_langugageseShikshak
 
Unit 1.3 types of cloud
Unit 1.3 types of cloudUnit 1.3 types of cloud
Unit 1.3 types of cloudeShikshak
 
Mesics lecture 8 arrays in 'c'
Mesics lecture 8   arrays in 'c'Mesics lecture 8   arrays in 'c'
Mesics lecture 8 arrays in 'c'eShikshak
 
Unit 1.1 introduction to cloud computing
Unit 1.1   introduction to cloud computingUnit 1.1   introduction to cloud computing
Unit 1.1 introduction to cloud computingeShikshak
 
Lecture19 unionsin c.ppt
Lecture19 unionsin c.pptLecture19 unionsin c.ppt
Lecture19 unionsin c.ppteShikshak
 
Unit 1.2 move to cloud computing
Unit 1.2   move to cloud computingUnit 1.2   move to cloud computing
Unit 1.2 move to cloud computingeShikshak
 
Introduction to multimedia
Introduction to multimediaIntroduction to multimedia
Introduction to multimediaeShikshak
 
Html forms
Html formsHtml forms
Html formseShikshak
 
Unit 1.4 working of cloud computing
Unit 1.4 working of cloud computingUnit 1.4 working of cloud computing
Unit 1.4 working of cloud computingeShikshak
 
C Pointers
C PointersC Pointers
C Pointersomukhtar
 
Language processors
Language processorsLanguage processors
Language processorseShikshak
 

Andere mochten auch (19)

Unit 6 pointers
Unit 6   pointersUnit 6   pointers
Unit 6 pointers
 
Pointers in C
Pointers in CPointers in C
Pointers in C
 
Lecture 11 css_inculsion
Lecture 11 css_inculsionLecture 11 css_inculsion
Lecture 11 css_inculsion
 
Introduction to computer_and_its_structure
Introduction to computer_and_its_structureIntroduction to computer_and_its_structure
Introduction to computer_and_its_structure
 
Introduction to css
Introduction to cssIntroduction to css
Introduction to css
 
Lecture 12 css_fonts
Lecture 12 css_fontsLecture 12 css_fonts
Lecture 12 css_fonts
 
Program development cyle
Program development cyleProgram development cyle
Program development cyle
 
Computer programming programming_langugages
Computer programming programming_langugagesComputer programming programming_langugages
Computer programming programming_langugages
 
Unit 1.3 types of cloud
Unit 1.3 types of cloudUnit 1.3 types of cloud
Unit 1.3 types of cloud
 
Mesics lecture 8 arrays in 'c'
Mesics lecture 8   arrays in 'c'Mesics lecture 8   arrays in 'c'
Mesics lecture 8 arrays in 'c'
 
Unit 1.1 introduction to cloud computing
Unit 1.1   introduction to cloud computingUnit 1.1   introduction to cloud computing
Unit 1.1 introduction to cloud computing
 
Lecture19 unionsin c.ppt
Lecture19 unionsin c.pptLecture19 unionsin c.ppt
Lecture19 unionsin c.ppt
 
Unit 1.2 move to cloud computing
Unit 1.2   move to cloud computingUnit 1.2   move to cloud computing
Unit 1.2 move to cloud computing
 
Introduction to multimedia
Introduction to multimediaIntroduction to multimedia
Introduction to multimedia
 
Html forms
Html formsHtml forms
Html forms
 
Unit 1.4 working of cloud computing
Unit 1.4 working of cloud computingUnit 1.4 working of cloud computing
Unit 1.4 working of cloud computing
 
Pointers
PointersPointers
Pointers
 
C Pointers
C PointersC Pointers
C Pointers
 
Language processors
Language processorsLanguage processors
Language processors
 

Ähnlich wie Lecturer23 pointersin c.ppt

COM1407: Working with Pointers
COM1407: Working with PointersCOM1407: Working with Pointers
COM1407: Working with PointersHemantha Kulathilake
 
Chapter16 pointer
Chapter16 pointerChapter16 pointer
Chapter16 pointerDeepak Singh
 
Chapter 5 (Part I) - Pointers.pdf
Chapter 5 (Part I) - Pointers.pdfChapter 5 (Part I) - Pointers.pdf
Chapter 5 (Part I) - Pointers.pdfTamiratDejene1
 
Pointers Refrences & dynamic memory allocation in C++
Pointers Refrences & dynamic memory allocation in C++Pointers Refrences & dynamic memory allocation in C++
Pointers Refrences & dynamic memory allocation in C++Gamindu Udayanga
 
Pointer basics.pptx
Pointer basics.pptxPointer basics.pptx
Pointer basics.pptxraghupedda55
 
Lecture2.ppt
Lecture2.pptLecture2.ppt
Lecture2.pptSabaunnisa3
 
Fundamentals of Programming Constructs.pptx
Fundamentals of  Programming Constructs.pptxFundamentals of  Programming Constructs.pptx
Fundamentals of Programming Constructs.pptxvijayapraba1
 
0-Slot11-12-Pointers.pdf
0-Slot11-12-Pointers.pdf0-Slot11-12-Pointers.pdf
0-Slot11-12-Pointers.pdfssusere19c741
 
Pointers and Array, pointer and String.pptx
Pointers and Array, pointer and String.pptxPointers and Array, pointer and String.pptx
Pointers and Array, pointer and String.pptxAnanthi Palanisamy
 
FYBSC(CS)_UNIT-1_Pointers in C.pptx
FYBSC(CS)_UNIT-1_Pointers in C.pptxFYBSC(CS)_UNIT-1_Pointers in C.pptx
FYBSC(CS)_UNIT-1_Pointers in C.pptxsangeeta borde
 
C programming session 05
C programming session 05C programming session 05
C programming session 05Dushmanta Nath
 
Used of Pointer in C++ Programming
Used of Pointer in C++ ProgrammingUsed of Pointer in C++ Programming
Used of Pointer in C++ ProgrammingAbdullah Jan
 

Ähnlich wie Lecturer23 pointersin c.ppt (20)

COM1407: Working with Pointers
COM1407: Working with PointersCOM1407: Working with Pointers
COM1407: Working with Pointers
 
Pointers
PointersPointers
Pointers
 
Chapter16 pointer
Chapter16 pointerChapter16 pointer
Chapter16 pointer
 
Types of pointer
Types of pointerTypes of pointer
Types of pointer
 
Chapter 5 (Part I) - Pointers.pdf
Chapter 5 (Part I) - Pointers.pdfChapter 5 (Part I) - Pointers.pdf
Chapter 5 (Part I) - Pointers.pdf
 
Advanced pointers
Advanced pointersAdvanced pointers
Advanced pointers
 
Pointers Refrences & dynamic memory allocation in C++
Pointers Refrences & dynamic memory allocation in C++Pointers Refrences & dynamic memory allocation in C++
Pointers Refrences & dynamic memory allocation in C++
 
Lecture 18 - Pointers
Lecture 18 - PointersLecture 18 - Pointers
Lecture 18 - Pointers
 
C programming session8
C programming  session8C programming  session8
C programming session8
 
C programming session8
C programming  session8C programming  session8
C programming session8
 
Pointer basics.pptx
Pointer basics.pptxPointer basics.pptx
Pointer basics.pptx
 
Lecture2.ppt
Lecture2.pptLecture2.ppt
Lecture2.ppt
 
Fundamentals of Programming Constructs.pptx
Fundamentals of  Programming Constructs.pptxFundamentals of  Programming Constructs.pptx
Fundamentals of Programming Constructs.pptx
 
0-Slot11-12-Pointers.pdf
0-Slot11-12-Pointers.pdf0-Slot11-12-Pointers.pdf
0-Slot11-12-Pointers.pdf
 
Pointers and Array, pointer and String.pptx
Pointers and Array, pointer and String.pptxPointers and Array, pointer and String.pptx
Pointers and Array, pointer and String.pptx
 
FYBSC(CS)_UNIT-1_Pointers in C.pptx
FYBSC(CS)_UNIT-1_Pointers in C.pptxFYBSC(CS)_UNIT-1_Pointers in C.pptx
FYBSC(CS)_UNIT-1_Pointers in C.pptx
 
C programming session 05
C programming session 05C programming session 05
C programming session 05
 
PSPC--UNIT-5.pdf
PSPC--UNIT-5.pdfPSPC--UNIT-5.pdf
PSPC--UNIT-5.pdf
 
Pointers
PointersPointers
Pointers
 
Used of Pointer in C++ Programming
Used of Pointer in C++ ProgrammingUsed of Pointer in C++ Programming
Used of Pointer in C++ Programming
 

Mehr von eShikshak

Modelling and evaluation
Modelling and evaluationModelling and evaluation
Modelling and evaluationeShikshak
 
Operators in python
Operators in pythonOperators in python
Operators in pythoneShikshak
 
Datatypes in python
Datatypes in pythonDatatypes in python
Datatypes in pythoneShikshak
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to pythoneShikshak
 
Introduction to e commerce
Introduction to e commerceIntroduction to e commerce
Introduction to e commerceeShikshak
 
Chapeter 2 introduction to cloud computing
Chapeter 2   introduction to cloud computingChapeter 2   introduction to cloud computing
Chapeter 2 introduction to cloud computingeShikshak
 
Mesics lecture files in 'c'
Mesics lecture   files in 'c'Mesics lecture   files in 'c'
Mesics lecture files in 'c'eShikshak
 
Mesics lecture 7 iteration and repetitive executions
Mesics lecture 7   iteration and repetitive executionsMesics lecture 7   iteration and repetitive executions
Mesics lecture 7 iteration and repetitive executionseShikshak
 
Mesics lecture 5 input – output in ‘c’
Mesics lecture 5   input – output in ‘c’Mesics lecture 5   input – output in ‘c’
Mesics lecture 5 input – output in ‘c’eShikshak
 
Mesics lecture 6 control statement = if -else if__else
Mesics lecture 6   control statement = if -else if__elseMesics lecture 6   control statement = if -else if__else
Mesics lecture 6 control statement = if -else if__elseeShikshak
 
Mesics lecture 4 c operators and experssions
Mesics lecture  4   c operators and experssionsMesics lecture  4   c operators and experssions
Mesics lecture 4 c operators and experssionseShikshak
 
Mesics lecture 5 input – output in ‘c’
Mesics lecture 5   input – output in ‘c’Mesics lecture 5   input – output in ‘c’
Mesics lecture 5 input – output in ‘c’eShikshak
 
Mesics lecture 3 c – constants and variables
Mesics lecture 3   c – constants and variablesMesics lecture 3   c – constants and variables
Mesics lecture 3 c – constants and variableseShikshak
 
Lecture 7 relational_and_logical_operators
Lecture 7 relational_and_logical_operatorsLecture 7 relational_and_logical_operators
Lecture 7 relational_and_logical_operatorseShikshak
 
Lecture21 categoriesof userdefinedfunctions.ppt
Lecture21 categoriesof userdefinedfunctions.pptLecture21 categoriesof userdefinedfunctions.ppt
Lecture21 categoriesof userdefinedfunctions.ppteShikshak
 
Lecture20 user definedfunctions.ppt
Lecture20 user definedfunctions.pptLecture20 user definedfunctions.ppt
Lecture20 user definedfunctions.ppteShikshak
 
Lecture18 structurein c.ppt
Lecture18 structurein c.pptLecture18 structurein c.ppt
Lecture18 structurein c.ppteShikshak
 
Lecture17 arrays.ppt
Lecture17 arrays.pptLecture17 arrays.ppt
Lecture17 arrays.ppteShikshak
 
Lecture15 comparisonoftheloopcontrolstructures.ppt
Lecture15 comparisonoftheloopcontrolstructures.pptLecture15 comparisonoftheloopcontrolstructures.ppt
Lecture15 comparisonoftheloopcontrolstructures.ppteShikshak
 
Lecture13 control statementswitch.ppt
Lecture13 control statementswitch.pptLecture13 control statementswitch.ppt
Lecture13 control statementswitch.ppteShikshak
 

Mehr von eShikshak (20)

Modelling and evaluation
Modelling and evaluationModelling and evaluation
Modelling and evaluation
 
Operators in python
Operators in pythonOperators in python
Operators in python
 
Datatypes in python
Datatypes in pythonDatatypes in python
Datatypes in python
 
Introduction to python
Introduction to pythonIntroduction to python
Introduction to python
 
Introduction to e commerce
Introduction to e commerceIntroduction to e commerce
Introduction to e commerce
 
Chapeter 2 introduction to cloud computing
Chapeter 2   introduction to cloud computingChapeter 2   introduction to cloud computing
Chapeter 2 introduction to cloud computing
 
Mesics lecture files in 'c'
Mesics lecture   files in 'c'Mesics lecture   files in 'c'
Mesics lecture files in 'c'
 
Mesics lecture 7 iteration and repetitive executions
Mesics lecture 7   iteration and repetitive executionsMesics lecture 7   iteration and repetitive executions
Mesics lecture 7 iteration and repetitive executions
 
Mesics lecture 5 input – output in ‘c’
Mesics lecture 5   input – output in ‘c’Mesics lecture 5   input – output in ‘c’
Mesics lecture 5 input – output in ‘c’
 
Mesics lecture 6 control statement = if -else if__else
Mesics lecture 6   control statement = if -else if__elseMesics lecture 6   control statement = if -else if__else
Mesics lecture 6 control statement = if -else if__else
 
Mesics lecture 4 c operators and experssions
Mesics lecture  4   c operators and experssionsMesics lecture  4   c operators and experssions
Mesics lecture 4 c operators and experssions
 
Mesics lecture 5 input – output in ‘c’
Mesics lecture 5   input – output in ‘c’Mesics lecture 5   input – output in ‘c’
Mesics lecture 5 input – output in ‘c’
 
Mesics lecture 3 c – constants and variables
Mesics lecture 3   c – constants and variablesMesics lecture 3   c – constants and variables
Mesics lecture 3 c – constants and variables
 
Lecture 7 relational_and_logical_operators
Lecture 7 relational_and_logical_operatorsLecture 7 relational_and_logical_operators
Lecture 7 relational_and_logical_operators
 
Lecture21 categoriesof userdefinedfunctions.ppt
Lecture21 categoriesof userdefinedfunctions.pptLecture21 categoriesof userdefinedfunctions.ppt
Lecture21 categoriesof userdefinedfunctions.ppt
 
Lecture20 user definedfunctions.ppt
Lecture20 user definedfunctions.pptLecture20 user definedfunctions.ppt
Lecture20 user definedfunctions.ppt
 
Lecture18 structurein c.ppt
Lecture18 structurein c.pptLecture18 structurein c.ppt
Lecture18 structurein c.ppt
 
Lecture17 arrays.ppt
Lecture17 arrays.pptLecture17 arrays.ppt
Lecture17 arrays.ppt
 
Lecture15 comparisonoftheloopcontrolstructures.ppt
Lecture15 comparisonoftheloopcontrolstructures.pptLecture15 comparisonoftheloopcontrolstructures.ppt
Lecture15 comparisonoftheloopcontrolstructures.ppt
 
Lecture13 control statementswitch.ppt
Lecture13 control statementswitch.pptLecture13 control statementswitch.ppt
Lecture13 control statementswitch.ppt
 

KĂŒrzlich hochgeladen

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesBoston Institute of Analytics
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Principled Technologies
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel AraĂșjo
 

KĂŒrzlich hochgeladen (20)

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 

Lecturer23 pointersin c.ppt

  • 1. POINTERS IN ‘C’ Prakash Khaire,Lecturer B V Patel Inst. of BMC & IT, GopalVidyanagar
  • 2. What is a variable? Each variable must be defined before you can ● use it inside your program. Did you ask yourself why we have to declare ● variables? ●First reason is To allocate memory ●Second reason is Instruct compiler how to treat this memory location ML? As int or float...
  • 3. What is a variable? int main() Three memory locations have { been allocated. int x = 16; float y = 2.3; ●The first memory location char z = 70; . holds int value. . . ● The second memory } location holds floating-point number. ●The last memory location holds one byte integer.
  • 4. What is a variable? ●A variable is a named memory location. ●Variables provide direct access to its memory location. ●Can you understand what will happen when you write: int x; X variable x = 44; 44 value 1638 address
  • 5. Memory Addresses Each Memory Location has an address ➔ each ● variable has an address. Memory address in 32-bit Machines is 32-bit ● unsigned integer number. How to get the address of a variable? ● &variable_name int i=15; ● printf(“%d ● %u”,i,&i); &i returns the address of i. ●
  • 6. Pointer Variables ● Ask yourself: ●What is an integer variable? ●What is a floating-point variable? ●What is a character variable? ● Now, what is a pointer variable? ● It is a variable that stores the memory address. OR ● It points to a storage locations of memory. OR ● Pointers contain memory addresses as their values.
  • 7. Declaring Pointer Variables Like ordinary variables, pointer variable must be ● declared before they are used. Declaration form ● ● datatype *pointer_variable; ●The * tells the compiler that this is pointer variable ●Pointer_variable will point to the given datatype ● Declaration Style ●int* iptr; ●int *iptr; ●int * iptr;
  • 8. Example ● int *iptr; iptr is pointer variable of integer data type, it will store the ● memory address of int data type. ● float *fptr; fptr is pointer variable of float data type, it will store memory ● address of float data type. ● char *cptr; cptr is pointer variable of character data type, it will store ● memory address of character data type.
  • 9. Suspicious Pointer Conversion When you assign a particular type of pointer ● variable with address of different type, such type of automatic type conversion is known as suspicious type conversion. In turbo c compiler it is not cause of any ● compilation error but compiler will send one warning message: suspicious pointer conversion. So we should avoid suspicious pointer conversion.
  • 10. Generic Pointer ●void pointer in c is known as generic pointer. Literal meaning of generic pointer is a pointer which can point type of data. ●void *ptr; ●Here ptr is generic pointer. NULL pointer is a pointer which is pointing to nothing. ● NULL pointer points the base address of segment. ●int *ptr=(char *)0; ●float *ptr=(float *)0; ●char *ptr=(char *)0; ●double *ptr=(double *)0; ●char *ptr=’0’; ●int *ptr=NULL; NULL is macro constant which has been defined in the ● heard file stdio.h, alloc.h, mem.h, stddef.h and stdlib.h as
  • 11. wild pointer A pointer in c which has not been initialized is ● known as wild pointer. ● Example: void main() { int *ptr; Output: Any address printf("%un",ptr); Garbage value printf("%d",*ptr); }
  • 12. Dangling pointer ●If any pointer is pointing the memory address of any variable but after some time that variable has been deleted from that memory location while pointer is still pointing such memory location. Such pointer is known as dangling pointer and this problem is known as dangling pointer problem.
  • 13. Arithmetic Operations with Pointer Like ordinary variables, pointer variables can also be used as a ● part of expression. The following rules are applied when we perform arithmetic ● operations on pointer variables. ●Address + Number= Address ●Address - Number= Address ●Address++ = Address ●Address-- = Address ●++Address = Address ●--Address = Address ●If we will add or subtract a number from an address result will also be an address
  • 14. Benefits of using pointer ●Efficient in handling arrays and data tables. ●Returns multiple values from a function. ●Use of pointer arrays to character strings results in saving of data storage space in memory. ●Supports dynamic memory management. ●Can manipulate dynamic data structure. ●Increases execution speed and reduces execution time