SlideShare uma empresa Scribd logo
1 de 23
Baixar para ler offline
C Course
          By
   Fady Mohammed Osman

Mail:Fady_moa@yahoo.com
Variables

   Variables are places for holding data in
     memory.
   C data types are:
   void.
   char.
   int.
   float.
   double.
Naming rules

   Must start with a character or an underscore
    only.
   Form second letter and on, it can be a
    character, a digit, or an underscore.
   Shall not take the name of language reserved
    keywords (if, for, while, etc...)
   It is case sensitive.
Scope of variables

   Local variables:
    declared inside function and can only be
    accessed inside that function.
   Formal parameters :
    special case of local variables declared inside
    function prototype.
   Global variables:
    declared outside any function and can be
    accessed from any where in the program.
Life time

   Can be defined as the duration of the program
    during which the variable is accessible.
   This may be all the time of the program
    excution (global and static).
   Or only limited to the time of excution of a
    function(local and formal parameters).
Type modifiers

   signed.
   unsigned.
   short.
   long.
Type sizes and range
   Common size in a 80x86 machine:
   char 8 bit (1 byte).
   short 16 bit (2 byte).
   int 32 bit (4 byte which is the word size).
   long int (4 byte).
   long long int (8 byte).
   float 32 bit (4 byte).
   double 64 bit (8 byte).
   long double 64 bit (8 bytes).
The general rule

   This rule is always true.
   short<=int<=long<=long long.
   int is at least 16 bit.
   long is at least 32 bit.
   long long is at least 64 bit.
Storage specifiers

   auto.
   register.
   static.
   extern.
register keyword

   It tells the compiler to store a variable in such a
    way that it can be accessed as quickly as
    possible (i.e. In a register).
   The comiler can sometimes ignore this since
    there's only samll number of registers available.
   A good practice is to use this keyword with
    variables that control or accessed in loops.
   Today most optimized compilers do this
    automatically.
static

   Local static variables:
   When applied to a local variables it allows it to
    maintain its value between function calls (its
    value isn't lost when the function returns).
   Global static variables:
   It tells the compiler to create a global variable
    that is only seen within the file where it was
    declared so we can link it with any file without
    fear of side effects i.e another global variable
    with the same name.
extern keyword

   Used when you have a multiple files and one of
    them contains a gloabal variables.in order to
    make this global variable seen by other files we
    use the extern keyword.
Type qualifiers

   const.
   volatile.
   restrict.
const keyword

   The variable value cannot have it's value
    changed during the excution of the program.
volatile keyword
   It tells the compiler that the value of the variable
    may change at any time--without any action
    being taken by the code the compiler finds
    nearby.
   Problems that volatile can solve in embedded
    world:
    - Code that works fine--until you enable
    compiler optimizations .
    - Code that works fine--until interrupts are
    enabled.
    - RTOS tasks that work fine in isolation--until
    some other task is spawned.
Proper use of volatile

   Proper use of volatile:
    1. Memory-mapped peripheral registers.
    2. Global variables modified by an interrupt
    service routine .
    3. Global variables accessed by multiple tasks
    within a multi-threaded application.
Restrict keyword

   Will be explained later when talking about
    pointers.
stdint.h file

   This header is particularly useful for embedded
    programming which often involves considerable
    manipulation of hardware specific I/O registers
    requiring integer data of fixed widths, specific
    locations and exact alignments.
Specific integral type limits
C99 new types

   _Bool.
   _Complex.
   _Imaginary.
_Bool

   A variable of size 1 byte.
   Can contain a true (1) or false (0).
   Where true and false are preprocessor macros
    defined in the header file stdbool.h.
   Be ware when using the ++ and - - operator.
   When assigning any other value than 0 it'll
    return 1(true).
_Complex and _Imaginary

   Rarly used types.
   used in scientific programs.
   Also a library of c functions using the header
    file <complex.h> .
   Declaration:
   float _Complex or double _Complex.
   float _Complex is 8 bytes.
   double _Complex is 16 bytes.

Mais conteúdo relacionado

Mais procurados

Overview of c language
Overview of c languageOverview of c language
Overview of c language
shalini392
 

Mais procurados (19)

Looping statements
Looping statementsLooping statements
Looping statements
 
Introduction To Programming with Python Lecture 2
Introduction To Programming with Python Lecture 2Introduction To Programming with Python Lecture 2
Introduction To Programming with Python Lecture 2
 
Pc module1
Pc module1Pc module1
Pc module1
 
Escape Sequences and Variables
Escape Sequences and VariablesEscape Sequences and Variables
Escape Sequences and Variables
 
C language UPTU Unit3 Slides
C language UPTU Unit3 SlidesC language UPTU Unit3 Slides
C language UPTU Unit3 Slides
 
Lecture13 control statementswitch.ppt
Lecture13 control statementswitch.pptLecture13 control statementswitch.ppt
Lecture13 control statementswitch.ppt
 
C language
C languageC language
C language
 
Quick 3GPP RRC ASN.1
Quick 3GPP RRC ASN.1Quick 3GPP RRC ASN.1
Quick 3GPP RRC ASN.1
 
C Programming - Refresher - Part III
C Programming - Refresher - Part IIIC Programming - Refresher - Part III
C Programming - Refresher - Part III
 
Clean code
Clean codeClean code
Clean code
 
Sp imp gtu
Sp imp gtuSp imp gtu
Sp imp gtu
 
Overview of c language
Overview of c languageOverview of c language
Overview of c language
 
Turing machine and Halting Introduction
Turing machine and Halting IntroductionTuring machine and Halting Introduction
Turing machine and Halting Introduction
 
Getting started with c++
Getting started with c++Getting started with c++
Getting started with c++
 
Learning php 7
Learning php 7Learning php 7
Learning php 7
 
What is c language
What is c languageWhat is c language
What is c language
 
C language ppt
C language pptC language ppt
C language ppt
 
Symbol Table, Error Handler & Code Generation
Symbol Table, Error Handler & Code GenerationSymbol Table, Error Handler & Code Generation
Symbol Table, Error Handler & Code Generation
 
C programming session3
C programming  session3C programming  session3
C programming session3
 

Semelhante a 01 Variables

Storage Classes and Functions
Storage Classes and FunctionsStorage Classes and Functions
Storage Classes and Functions
Jake Bond
 

Semelhante a 01 Variables (20)

Technical Interview
Technical InterviewTechnical Interview
Technical Interview
 
Java platform
Java platformJava platform
Java platform
 
C programming session7
C programming  session7C programming  session7
C programming session7
 
C programming session7
C programming  session7C programming  session7
C programming session7
 
Introduction to c
Introduction to cIntroduction to c
Introduction to c
 
venkatesh.pptx
venkatesh.pptxvenkatesh.pptx
venkatesh.pptx
 
Storage Class Specifiers in C++
Storage Class Specifiers in C++Storage Class Specifiers in C++
Storage Class Specifiers in C++
 
Storage classes in c language
Storage classes in c languageStorage classes in c language
Storage classes in c language
 
Storage classes in c language
Storage classes in c languageStorage classes in c language
Storage classes in c language
 
C, C++ Interview Questions Part - 1
C, C++ Interview Questions Part - 1C, C++ Interview Questions Part - 1
C, C++ Interview Questions Part - 1
 
Storage classes
Storage classesStorage classes
Storage classes
 
Terms and Definitions.pdf
Terms and Definitions.pdfTerms and Definitions.pdf
Terms and Definitions.pdf
 
Storage classess of C progamming
Storage classess of C progamming Storage classess of C progamming
Storage classess of C progamming
 
Operator Overloading and Scope of Variable
Operator Overloading and Scope of VariableOperator Overloading and Scope of Variable
Operator Overloading and Scope of Variable
 
Lecture2_MCS4_Evening.pptx
Lecture2_MCS4_Evening.pptxLecture2_MCS4_Evening.pptx
Lecture2_MCS4_Evening.pptx
 
FUNCTION CPU
FUNCTION CPUFUNCTION CPU
FUNCTION CPU
 
Storage Classes and Functions
Storage Classes and FunctionsStorage Classes and Functions
Storage Classes and Functions
 
Introduction to Visual Basic
Introduction to Visual Basic Introduction to Visual Basic
Introduction to Visual Basic
 
C- language Lecture 6
C- language Lecture 6C- language Lecture 6
C- language Lecture 6
 
Introduction to C++ Programming
Introduction to C++ ProgrammingIntroduction to C++ Programming
Introduction to C++ Programming
 

Mais de Learn 2 Be (10)

Programming Concepts 01
Programming Concepts 01Programming Concepts 01
Programming Concepts 01
 
Session2
Session2Session2
Session2
 
Session4
Session4Session4
Session4
 
Linux Introduction
Linux IntroductionLinux Introduction
Linux Introduction
 
Session1
Session1Session1
Session1
 
00 Intro
00  Intro00  Intro
00 Intro
 
Session3
Session3Session3
Session3
 
Cryptography
CryptographyCryptography
Cryptography
 
Linux1
Linux1Linux1
Linux1
 
L2 B Embedded Systems
L2 B Embedded SystemsL2 B Embedded Systems
L2 B Embedded Systems
 

Último

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
Enterprise Knowledge
 

Último (20)

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
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
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
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
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)
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
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
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
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
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
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...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
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
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
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
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 

01 Variables

  • 1.
  • 2. C Course By Fady Mohammed Osman Mail:Fady_moa@yahoo.com
  • 3. Variables  Variables are places for holding data in memory.  C data types are:  void.  char.  int.  float.  double.
  • 4. Naming rules  Must start with a character or an underscore only.  Form second letter and on, it can be a character, a digit, or an underscore.  Shall not take the name of language reserved keywords (if, for, while, etc...)  It is case sensitive.
  • 5. Scope of variables  Local variables: declared inside function and can only be accessed inside that function.  Formal parameters : special case of local variables declared inside function prototype.  Global variables: declared outside any function and can be accessed from any where in the program.
  • 6. Life time  Can be defined as the duration of the program during which the variable is accessible.  This may be all the time of the program excution (global and static).  Or only limited to the time of excution of a function(local and formal parameters).
  • 7. Type modifiers  signed.  unsigned.  short.  long.
  • 8. Type sizes and range  Common size in a 80x86 machine:  char 8 bit (1 byte).  short 16 bit (2 byte).  int 32 bit (4 byte which is the word size).  long int (4 byte).  long long int (8 byte).  float 32 bit (4 byte).  double 64 bit (8 byte).  long double 64 bit (8 bytes).
  • 9. The general rule  This rule is always true.  short<=int<=long<=long long.  int is at least 16 bit.  long is at least 32 bit.  long long is at least 64 bit.
  • 10. Storage specifiers  auto.  register.  static.  extern.
  • 11. register keyword  It tells the compiler to store a variable in such a way that it can be accessed as quickly as possible (i.e. In a register).  The comiler can sometimes ignore this since there's only samll number of registers available.  A good practice is to use this keyword with variables that control or accessed in loops.  Today most optimized compilers do this automatically.
  • 12. static  Local static variables:  When applied to a local variables it allows it to maintain its value between function calls (its value isn't lost when the function returns).  Global static variables:  It tells the compiler to create a global variable that is only seen within the file where it was declared so we can link it with any file without fear of side effects i.e another global variable with the same name.
  • 13. extern keyword  Used when you have a multiple files and one of them contains a gloabal variables.in order to make this global variable seen by other files we use the extern keyword.
  • 14. Type qualifiers  const.  volatile.  restrict.
  • 15. const keyword  The variable value cannot have it's value changed during the excution of the program.
  • 16. volatile keyword  It tells the compiler that the value of the variable may change at any time--without any action being taken by the code the compiler finds nearby.  Problems that volatile can solve in embedded world: - Code that works fine--until you enable compiler optimizations . - Code that works fine--until interrupts are enabled. - RTOS tasks that work fine in isolation--until some other task is spawned.
  • 17. Proper use of volatile  Proper use of volatile: 1. Memory-mapped peripheral registers. 2. Global variables modified by an interrupt service routine . 3. Global variables accessed by multiple tasks within a multi-threaded application.
  • 18. Restrict keyword  Will be explained later when talking about pointers.
  • 19. stdint.h file  This header is particularly useful for embedded programming which often involves considerable manipulation of hardware specific I/O registers requiring integer data of fixed widths, specific locations and exact alignments.
  • 21. C99 new types  _Bool.  _Complex.  _Imaginary.
  • 22. _Bool  A variable of size 1 byte.  Can contain a true (1) or false (0).  Where true and false are preprocessor macros defined in the header file stdbool.h.  Be ware when using the ++ and - - operator.  When assigning any other value than 0 it'll return 1(true).
  • 23. _Complex and _Imaginary  Rarly used types.  used in scientific programs.  Also a library of c functions using the header file <complex.h> .  Declaration:  float _Complex or double _Complex.  float _Complex is 8 bytes.  double _Complex is 16 bytes.