SlideShare a Scribd company logo
1 of 17
Storage classes
• A variable in C can have any one of the four
  storage classes.
     1. Automatic variables.
     2. External variables.
     3. Static variables.
     4. Register variables.
AUTOMATIC VARIABLES (LOCAL/INTERNAL)
• Automatic variables are declared inside a function
  in which they are to be utilized.
• They are created when a function is called and
  destroyed automatically when the function is
  exited.
• Eg:main()
  {
      int number;
  }
• We may also use the keyword auto to declare
  automatic variables explicitly.
EXTERNAL VARIABLES
• Variables that are both alive and active throughout
  the entire program are known as external variables.
  They are also known as global variables.
  extern float length = 7.5;
  void main()
  {
  }
  function1( )
  {
  }The keyword extern can be used for explicit
  declarations of external variables.
STATIC VARIABLES
• As the name suggests, the value of a static
  variable persists until the end of the program.
  A variable can be declared static using the
  keyword static.
• Eg:
• 1) static int x;
• 2) static int y;
REGISTER VARIABLES
• We can tell the compiler that a variable
  should be kept in one of the machine’s
  registers, instead of keeping in the memory.

• Since a register access is much faster than a
  memory access, keeping the frequently
  accessed variables in the register will lead to
  faster execution of programs.

• This is done as follows:
     register int count;
POINTERS
• A pointer is a variable that represents the location of a
  data item, such as a variable or an array element.

• A pointer is a memory address.

• In the simplest term pointer is a nearly integer variable
  which stores a memory address of a computer which
  may contain other variable or even another pointer.
Concept of Address and Pointers
• Memory       can  be       ADDR1
                             ADDR2
                                      Contents1

  conceptualized as a        ADDR3
                             ADDR4
  linear set of data         ADDR5
                             ADDR6
  locations.                   *
                               *
                               *

• Variables reference the    ADDR11   Contents11

  contents of a locations      *
                               *

                             ADDR16   Contents16

• Pointers have a value of
  the address of a given
  location
Pointer Variable
• Declaring a pointer variable is quite similar to
  declaring an normal variable all you have to do
  is to insert a star '*' operator before it.

• General form of pointer declaration is -
           type* name;
  For Example
           int * variable1;
• Say you declare a variable named foo.
                    int foo;
• Now let's declare another variable of pointer
  type
             int *foo_ptr = &foo;
  foo_ptr is declared as a pointer to int. We have
  initialized it to point to foo.
Use of & and *

• When is & used?
• When is * used?

• & -- "address operator" which gives or
  produces the memory address of a data
  variable.

• * -- "dereferencing operator" which provides
  the contents in the memory location specified
  by a pointer
#include <stdio.h>
void main (void)
{
   int count = 10, x;
   int *int_pointer;
   int_pointer = &count;
   x = *int_pointer;
   printf ("count = %d, x = %dn", count, x);
}
Using Pointers in Expressions
  #include <stdio.h>
  void main ()
  { int i1, i2;
      int *p1;
      i1 = 5;
      p1 = &i1;
      i2 = *p1 + 20;
printf ("i1 = %d, i2 = %d, *p1 = %d ", i1, i2, *p1);
}
Pointer arithmetic
• Pointers can be added and subtracted.

• However pointer arithmetic is quite meaningless
  unless performed on arrays.

• Addition and subtraction are mainly for moving
  forward and backward in an array.
#include <stdio.h>
void main()
{
  int ArrayA[3]={1,2,3};
  int *ptr;
  ptr=ArrayA;
  printf("address: %p - array value:%d “,ptr,*ptr);
  ptr++;
  printf("address: %p – array value:%d”,ptr,*ptr);
}
Pointers and Functions
• Pointers can be used to pass addresses of
  variables to called functions, thus allowing the
  called function to alter the values stored
  there.

• There are two mechanism to call a function
  1) Pass by Value
  2) Pass By Reference
Pass by Value
#include <stdio.h>
void main ( )
{
  int a = 5, b = 6;               Results:
  printf("a=%d b=%dn",a,b) ;           a=5 b=6
  swap (a, b) ;                         a=6 b=5
  printf("a=%d b=%dn",a,b) ;           a=5 b=6
}
void swap(int a, int b)
{
  int temp;
  temp= a; a= b; b = temp ;
  printf ("a=%d b=%dn", a, b);
}
Pass by Reference
#include <stdio.h>
void main ( )
{
     int a = 5, b = 6;
                                       Results:
     printf("a=%d b=%dn",a,b) ;
                                             a=5 b=6
     swap (&a, &b) ;                         a=6 b=5
     printf("a=%d b=%dn",a,b) ;             a=6 b=5
}
void swap(int *a, int *b)
{
     int temp;
     temp=*a; *a=*b; *b = temp ;
     printf ("a=%d b=%dn", *a, *b);
}

More Related Content

What's hot (20)

Stack organization
Stack organizationStack organization
Stack organization
 
Pointers in c++
Pointers in c++Pointers in c++
Pointers in c++
 
Used of Pointer in C++ Programming
Used of Pointer in C++ ProgrammingUsed of Pointer in C++ Programming
Used of Pointer in C++ Programming
 
pointers
pointerspointers
pointers
 
Pointers in c++
Pointers in c++Pointers in c++
Pointers in c++
 
10. array & pointer
10. array & pointer10. array & pointer
10. array & pointer
 
Pointer in C++
Pointer in C++Pointer in C++
Pointer in C++
 
Pointer in c++ part2
Pointer in c++ part2Pointer in c++ part2
Pointer in c++ part2
 
9 Arrays
9 Arrays9 Arrays
9 Arrays
 
This pointer
This pointerThis pointer
This pointer
 
Pointers in C language
Pointers  in  C languagePointers  in  C language
Pointers in C language
 
What's new in java 8
What's new in java 8What's new in java 8
What's new in java 8
 
Tail Recursion in data structure
Tail Recursion in data structureTail Recursion in data structure
Tail Recursion in data structure
 
Unit 6 pointers
Unit 6   pointersUnit 6   pointers
Unit 6 pointers
 
Program activation records
Program activation recordsProgram activation records
Program activation records
 
Csa stack
Csa stackCsa stack
Csa stack
 
Array of pointer
Array of pointerArray of pointer
Array of pointer
 
Pointers
PointersPointers
Pointers
 
Functional programming java
Functional programming javaFunctional programming java
Functional programming java
 
358 33 powerpoint-slides_9-stacks-queues_chapter-9
358 33 powerpoint-slides_9-stacks-queues_chapter-9358 33 powerpoint-slides_9-stacks-queues_chapter-9
358 33 powerpoint-slides_9-stacks-queues_chapter-9
 

Viewers also liked

New Products Or New Markets
New Products Or New MarketsNew Products Or New Markets
New Products Or New MarketsPico Lantini
 
CarParkFireSafety_UG_20091208
CarParkFireSafety_UG_20091208CarParkFireSafety_UG_20091208
CarParkFireSafety_UG_20091208Bart Merci
 
The Product Manager Should Be CEO
The Product Manager Should Be CEOThe Product Manager Should Be CEO
The Product Manager Should Be CEOPico Lantini
 
UG_20090206_Merci
UG_20090206_MerciUG_20090206_Merci
UG_20090206_MerciBart Merci
 
Bideo-Jolasak
Bideo-JolasakBideo-Jolasak
Bideo-Jolasakolatzucin
 

Viewers also liked (6)

New Products Or New Markets
New Products Or New MarketsNew Products Or New Markets
New Products Or New Markets
 
CarParkFireSafety_UG_20091208
CarParkFireSafety_UG_20091208CarParkFireSafety_UG_20091208
CarParkFireSafety_UG_20091208
 
Session 6
Session 6Session 6
Session 6
 
The Product Manager Should Be CEO
The Product Manager Should Be CEOThe Product Manager Should Be CEO
The Product Manager Should Be CEO
 
UG_20090206_Merci
UG_20090206_MerciUG_20090206_Merci
UG_20090206_Merci
 
Bideo-Jolasak
Bideo-JolasakBideo-Jolasak
Bideo-Jolasak
 

Similar to Session 5

pointer, structure ,union and intro to file handling
pointer, structure ,union and intro to file handlingpointer, structure ,union and intro to file handling
pointer, structure ,union and intro to file handlingRai University
 
PPS-POINTERS.pptx
PPS-POINTERS.pptxPPS-POINTERS.pptx
PPS-POINTERS.pptxsajinis3
 
Mca 1 pic u-5 pointer, structure ,union and intro to file handling
Mca 1 pic u-5 pointer, structure ,union and intro to file handlingMca 1 pic u-5 pointer, structure ,union and intro to file handling
Mca 1 pic u-5 pointer, structure ,union and intro to file handlingRai University
 
btech-1picu-5pointerstructureunionandintrotofilehandling-150122010700-conver.ppt
btech-1picu-5pointerstructureunionandintrotofilehandling-150122010700-conver.pptbtech-1picu-5pointerstructureunionandintrotofilehandling-150122010700-conver.ppt
btech-1picu-5pointerstructureunionandintrotofilehandling-150122010700-conver.pptchintuyadav19
 
Btech 1 pic u-5 pointer, structure ,union and intro to file handling
Btech 1 pic u-5 pointer, structure ,union and intro to file handlingBtech 1 pic u-5 pointer, structure ,union and intro to file handling
Btech 1 pic u-5 pointer, structure ,union and intro to file handlingRai University
 
pointer, structure ,union and intro to file handling
pointer, structure ,union and intro to file handlingpointer, structure ,union and intro to file handling
pointer, structure ,union and intro to file handlingRai University
 
Diploma ii cfpc- u-5.1 pointer, structure ,union and intro to file handling
Diploma ii  cfpc- u-5.1 pointer, structure ,union and intro to file handlingDiploma ii  cfpc- u-5.1 pointer, structure ,union and intro to file handling
Diploma ii cfpc- u-5.1 pointer, structure ,union and intro to file handlingRai University
 
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
 
Bsc cs 1 pic u-5 pointer, structure ,union and intro to file handling
Bsc cs 1 pic u-5 pointer, structure ,union and intro to file handlingBsc cs 1 pic u-5 pointer, structure ,union and intro to file handling
Bsc cs 1 pic u-5 pointer, structure ,union and intro to file handlingRai University
 
Advance topics of C language
Advance  topics of C languageAdvance  topics of C language
Advance topics of C languageMehwish Mehmood
 
358 33 powerpoint-slides_3-pointers_chapter-3
358 33 powerpoint-slides_3-pointers_chapter-3358 33 powerpoint-slides_3-pointers_chapter-3
358 33 powerpoint-slides_3-pointers_chapter-3sumitbardhan
 
Pointers in c - Mohammad Salman
Pointers in c - Mohammad SalmanPointers in c - Mohammad Salman
Pointers in c - Mohammad SalmanMohammadSalman129
 
Pointers and single &multi dimentionalarrays.pptx
Pointers and single &multi dimentionalarrays.pptxPointers and single &multi dimentionalarrays.pptx
Pointers and single &multi dimentionalarrays.pptxRamakrishna Reddy Bijjam
 

Similar to Session 5 (20)

pointer, structure ,union and intro to file handling
pointer, structure ,union and intro to file handlingpointer, structure ,union and intro to file handling
pointer, structure ,union and intro to file handling
 
C
CC
C
 
PPS-POINTERS.pptx
PPS-POINTERS.pptxPPS-POINTERS.pptx
PPS-POINTERS.pptx
 
Mca 1 pic u-5 pointer, structure ,union and intro to file handling
Mca 1 pic u-5 pointer, structure ,union and intro to file handlingMca 1 pic u-5 pointer, structure ,union and intro to file handling
Mca 1 pic u-5 pointer, structure ,union and intro to file handling
 
btech-1picu-5pointerstructureunionandintrotofilehandling-150122010700-conver.ppt
btech-1picu-5pointerstructureunionandintrotofilehandling-150122010700-conver.pptbtech-1picu-5pointerstructureunionandintrotofilehandling-150122010700-conver.ppt
btech-1picu-5pointerstructureunionandintrotofilehandling-150122010700-conver.ppt
 
Btech 1 pic u-5 pointer, structure ,union and intro to file handling
Btech 1 pic u-5 pointer, structure ,union and intro to file handlingBtech 1 pic u-5 pointer, structure ,union and intro to file handling
Btech 1 pic u-5 pointer, structure ,union and intro to file handling
 
pointer, structure ,union and intro to file handling
pointer, structure ,union and intro to file handlingpointer, structure ,union and intro to file handling
pointer, structure ,union and intro to file handling
 
Diploma ii cfpc- u-5.1 pointer, structure ,union and intro to file handling
Diploma ii  cfpc- u-5.1 pointer, structure ,union and intro to file handlingDiploma ii  cfpc- u-5.1 pointer, structure ,union and intro to file handling
Diploma ii cfpc- u-5.1 pointer, structure ,union and intro to file handling
 
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
 
Pointers
PointersPointers
Pointers
 
Bsc cs 1 pic u-5 pointer, structure ,union and intro to file handling
Bsc cs 1 pic u-5 pointer, structure ,union and intro to file handlingBsc cs 1 pic u-5 pointer, structure ,union and intro to file handling
Bsc cs 1 pic u-5 pointer, structure ,union and intro to file handling
 
Advanced pointers
Advanced pointersAdvanced pointers
Advanced pointers
 
Advance topics of C language
Advance  topics of C languageAdvance  topics of C language
Advance topics of C language
 
358 33 powerpoint-slides_3-pointers_chapter-3
358 33 powerpoint-slides_3-pointers_chapter-3358 33 powerpoint-slides_3-pointers_chapter-3
358 33 powerpoint-slides_3-pointers_chapter-3
 
Pointers in c - Mohammad Salman
Pointers in c - Mohammad SalmanPointers in c - Mohammad Salman
Pointers in c - Mohammad Salman
 
l7-pointers.ppt
l7-pointers.pptl7-pointers.ppt
l7-pointers.ppt
 
Lecture2.ppt
Lecture2.pptLecture2.ppt
Lecture2.ppt
 
Pointer.pptx
Pointer.pptxPointer.pptx
Pointer.pptx
 
ch08.ppt
ch08.pptch08.ppt
ch08.ppt
 
Pointers and single &multi dimentionalarrays.pptx
Pointers and single &multi dimentionalarrays.pptxPointers and single &multi dimentionalarrays.pptx
Pointers and single &multi dimentionalarrays.pptx
 

Recently uploaded

Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?XfilesPro
 
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetHyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetEnjoy Anytime
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsHyundai Motor Group
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxnull - The Open Security Community
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 

Recently uploaded (20)

Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?
 
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetHyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
 
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
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 

Session 5

  • 1. Storage classes • A variable in C can have any one of the four storage classes. 1. Automatic variables. 2. External variables. 3. Static variables. 4. Register variables.
  • 2. AUTOMATIC VARIABLES (LOCAL/INTERNAL) • Automatic variables are declared inside a function in which they are to be utilized. • They are created when a function is called and destroyed automatically when the function is exited. • Eg:main() { int number; } • We may also use the keyword auto to declare automatic variables explicitly.
  • 3. EXTERNAL VARIABLES • Variables that are both alive and active throughout the entire program are known as external variables. They are also known as global variables. extern float length = 7.5; void main() { } function1( ) { }The keyword extern can be used for explicit declarations of external variables.
  • 4. STATIC VARIABLES • As the name suggests, the value of a static variable persists until the end of the program. A variable can be declared static using the keyword static. • Eg: • 1) static int x; • 2) static int y;
  • 5. REGISTER VARIABLES • We can tell the compiler that a variable should be kept in one of the machine’s registers, instead of keeping in the memory. • Since a register access is much faster than a memory access, keeping the frequently accessed variables in the register will lead to faster execution of programs. • This is done as follows: register int count;
  • 6. POINTERS • A pointer is a variable that represents the location of a data item, such as a variable or an array element. • A pointer is a memory address. • In the simplest term pointer is a nearly integer variable which stores a memory address of a computer which may contain other variable or even another pointer.
  • 7. Concept of Address and Pointers • Memory can be ADDR1 ADDR2 Contents1 conceptualized as a ADDR3 ADDR4 linear set of data ADDR5 ADDR6 locations. * * * • Variables reference the ADDR11 Contents11 contents of a locations * * ADDR16 Contents16 • Pointers have a value of the address of a given location
  • 8. Pointer Variable • Declaring a pointer variable is quite similar to declaring an normal variable all you have to do is to insert a star '*' operator before it. • General form of pointer declaration is - type* name; For Example int * variable1;
  • 9. • Say you declare a variable named foo. int foo; • Now let's declare another variable of pointer type int *foo_ptr = &foo; foo_ptr is declared as a pointer to int. We have initialized it to point to foo.
  • 10. Use of & and * • When is & used? • When is * used? • & -- "address operator" which gives or produces the memory address of a data variable. • * -- "dereferencing operator" which provides the contents in the memory location specified by a pointer
  • 11. #include <stdio.h> void main (void) { int count = 10, x; int *int_pointer; int_pointer = &count; x = *int_pointer; printf ("count = %d, x = %dn", count, x); }
  • 12. Using Pointers in Expressions #include <stdio.h> void main () { int i1, i2; int *p1; i1 = 5; p1 = &i1; i2 = *p1 + 20; printf ("i1 = %d, i2 = %d, *p1 = %d ", i1, i2, *p1); }
  • 13. Pointer arithmetic • Pointers can be added and subtracted. • However pointer arithmetic is quite meaningless unless performed on arrays. • Addition and subtraction are mainly for moving forward and backward in an array.
  • 14. #include <stdio.h> void main() { int ArrayA[3]={1,2,3}; int *ptr; ptr=ArrayA; printf("address: %p - array value:%d “,ptr,*ptr); ptr++; printf("address: %p – array value:%d”,ptr,*ptr); }
  • 15. Pointers and Functions • Pointers can be used to pass addresses of variables to called functions, thus allowing the called function to alter the values stored there. • There are two mechanism to call a function 1) Pass by Value 2) Pass By Reference
  • 16. Pass by Value #include <stdio.h> void main ( ) { int a = 5, b = 6; Results: printf("a=%d b=%dn",a,b) ; a=5 b=6 swap (a, b) ; a=6 b=5 printf("a=%d b=%dn",a,b) ; a=5 b=6 } void swap(int a, int b) { int temp; temp= a; a= b; b = temp ; printf ("a=%d b=%dn", a, b); }
  • 17. Pass by Reference #include <stdio.h> void main ( ) { int a = 5, b = 6; Results: printf("a=%d b=%dn",a,b) ; a=5 b=6 swap (&a, &b) ; a=6 b=5 printf("a=%d b=%dn",a,b) ; a=6 b=5 } void swap(int *a, int *b) { int temp; temp=*a; *a=*b; *b = temp ; printf ("a=%d b=%dn", *a, *b); }