Your SlideShare is downloading. ×
0
01 Variables
01 Variables
01 Variables
01 Variables
01 Variables
01 Variables
01 Variables
01 Variables
01 Variables
01 Variables
01 Variables
01 Variables
01 Variables
01 Variables
01 Variables
01 Variables
01 Variables
01 Variables
01 Variables
01 Variables
01 Variables
01 Variables
01 Variables
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

01 Variables

408

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
408
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
12
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. C Course By Fady Mohammed Osman Mail:Fady_moa@yahoo.com
  • 2. Variables  Variables are places for holding data in memory.  C data types are:  void.  char.  int.  float.  double.
  • 3. 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.
  • 4. 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.
  • 5. 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).
  • 6. Type modifiers  signed.  unsigned.  short.  long.
  • 7. 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).
  • 8. 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.
  • 9. Storage specifiers  auto.  register.  static.  extern.
  • 10. 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.
  • 11. 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.
  • 12. 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.
  • 13. Type qualifiers  const.  volatile.  restrict.
  • 14. const keyword  The variable value cannot have it's value changed during the excution of the program.
  • 15. 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.
  • 16. 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.
  • 17. Restrict keyword  Will be explained later when talking about pointers.
  • 18. 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.
  • 19. Specific integral type limits
  • 20. C99 new types  _Bool.  _Complex.  _Imaginary.
  • 21. _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).
  • 22. _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.

×