Saturday, October 3, 2020

Data Types and storage class in C programming

 ANSI C support different 3 types of data types.

  1. Primary data types
    • int, (short,long,signed,unsigned) 
    • char, (signed,unsigned)
    • float,  (float,double,long double)
    • void 
  2. Derived data types
    • arrays
    • strings
    • structures
  3. User-Defined data type
    • typedef 
      • typedef <old name> <new name>;
    • enum identiifers
      • enum day [monday, tuesday, ... sunday];

Storage class and Scope 

  1. auto 
    • All local variables are auto.
    • Scope is limited to withing that funcation
  2. static
    • Variable retains its value even after funcation get exit
    • it get initialized by zero always
    • This variable is only visable in that file/translation unit
  3. extern
    • this variable is declared by someone else in another file or later in this file
    • extern int a;  -> this will not add any new memory in system
  4. register
    1. Ask compiler to store this register in any CPU register cache instead of memory because of frequent read/write of this variable

Declaring Variable as Constant (constant is a qualifier)

const int class_size = 40;

After this value of class_size can not be changed

Declaring Variable as volatile (volatile is a qualifier) 

volatile int class;

This tells the compiler that, value of class can be changed anytime by external sources (from outside the program)

class can be updated even class is not in left side of any assignment in that program. 

No comments:

Post a Comment