Monday 13 August 2012

C Programming Constructs


C Programming Constructs

In C Programming, we are using three important programming constructs.
1 .Variables
2. Expression
3. Data Types

Data Type :
          Data Type indicates the kind of Data.
Data Type are classified as two types.
1. Primitive
2. Derived

3 Basic - Primitive Types

     Type   - Memory in Byte - Range
1)  char    -            1            -128 to +127
2)  int       -            2            -32678 to +32767
3)  float    -            4            2 billion values

Derived Data Types
1. short int
2. long int
3. double
4. long double

Qualifiers
1.signed
2. unsigned


Variable :
In C Program, if you want to handle the data , you should store them temporarily in memory. For that, we have to use variable.
Variables are names used to assign some value temporarily in memory.
Technically, variables are named memory location used to store temporarily one data at a time.
To use the variable, first we have to declare them.

Syntax for variable Declaration :

 data_type variable_name [ = some value ] ;

Rules for variable Names
1. No Keyword
2. No number as a 1st Character
3. No blank space
4. No Special characters such as + - * / & @ etc...
5. may be short and meaningful.



Examples :


int char;   /* Invalid declaration  - No keyword*/
char 1A; /* Invalid declaration  - No number as a 1st Character*/
char A, B; /* valid declaration */
int  a,b,cd; /* valid declaration */
int A B; /* Invalid declaration  - No Blank space*/
int A, B=20; /* valid declaration */
int a+b; /* Invalid declaration  - Special char not allowed*/



Constant 
         The constant is like variable, The named Memory locations - used to store values. But  the values 
can not be modifiable.

1. Symbolic Constant : 
           Declared outside of all function - on the top of the program using #define 
                 #define pi 3.18

2. Constant  :  
          Declared  inside  the main() or inside any user defined functions
                 const float pi = 3.18 ;




Expression :
The combination of data and operators.
Ex. :  a+b
         a==b
        a >b

No comments:

Post a Comment