Thursday 1 December 2011

Basic C

1 . Study about    data types   and    C  basic
//----------------------------------------------------------------
a) constants : define or const

//-------------------------------------------------------------------------------------------------------
b) conditionals : if else , The ? operator , the  switch statement
//------------------------------------------------------------------------------------
arrays and strings
*  single and mutli arrays
  int a[10] ; // void input( int a[] , int n);
 int  a[10][10]  ; void input(int a[][100] , int n ,int m);
* char and strings
+a char assign with code number.It call  ascii  code   ;
+ value of char variable always  number  
+If char variable use  in C  programming , which  use  a character ,Now compiler convert it into character 
 example :char a ->97
Ascii Table
unsigned char  ( 0->255)
gets() and  scanf  is input from key
char a[81];
gets(a); // whitespace content 
Ascii Table
//--------------------------------------------------
//---------------------------------------------------
C string is defined as arrays of characters 
char  str[] = " helllo";// printf(" %s",str);
//-------------------------------------------------------------------------
data types
structures
//---------------------------------------------------
//--------------------------------------------------














//------------------------------------------------------------------------------------------------------
UNION

(Little Endian  or Big Endian  ? )
#include <stdio.h>
#include <conio.h>
union  point
{
int x ;
char c;
long l;
float f;
};
int main()
{
     union point a;
a.x = 97;
printf(" int x =   %d " , a.x);
printf("\nchar c =  %c " , a.c); 
printf("\nlong =   %ld" , a.l);
printf("\nfloat =   %f" , a.f);
//---------------------------------------
 a.c = 'b';
     printf("\nint x =   %d " , a.x);
printf("\nchar c =  %c " , a.c); 
printf("\nlong =   %ld" , a.l);
printf("\nfloat =   %f" , a.f);
//---------------------------------------
a.x = 300;
printf(" int x =   %d " , a.x);
printf("\nchar c =  %c " , a.c); 
printf("\nlong =   %ld" , a.l);
printf("\nfloat =   %f" , a.f);
//----------------------------------------
getch(); 
return 0;
}
struct point
{
  int a ;
  int y;
  union a  x;
}
Enumerated
Enumerated types contain a list of constants 
enum days {mon, tues, ..., sun} week; // start = 0 ,after start ++


+ static-  extern
static variable and extern variable is same  basic  but different   range
 - same : external variables  ( extern )
 - different :  +static only use in a file

#include <stdio.h>
#include <conio.h>
static int y  ;
void  fun1()
{
static int  x = 1;
printf("\nx = %d", x++);
y++ ;
}
void fun2()
{
   y++;
}
int main()
{
register int z = 10;
    fun1(); // 1 
fun1(); // 2
fun2();
printf("\ny = %d", y); //3
printf("\nz = %d", z); //10
getch(); 
return 0;
}

+ register
--------------------------------------------------------------------------

No comments:

Post a Comment