C language is rich in data types ANSI – American National Standard Institute ANSI C Supports Three classes of data types.

  1. Primary data type(fundamental)
  2. Derived data types
  3. User defined data types

All "C" compiler supports 5 fundamental data types

  1. Integer (int)
  2. Character (char)
  3. floating point (float)
  4. double-precession (double)
  5. void

Range of data types

Data type	Bytes in Ram	Range of data type
Char		1 bytes		-128 to 127
int		2 bytes		-32, 768 to 32,767
float		4 bytes		3.4c-38 to 3.4 c+ 38
double		8 bytes		1.7C – 308 to 1.7c +308

Integer Types :

Integers are whole numbers with a range of variables supported by a particular machine. In a signed integer uses one bit for sign and 15 bits for magnitude C has three classes of integer storage short int

1. int
2. long int      It has a set of qualifiers i.e.,
(1)sign qualifier
(2) unsigned qualifier
short int uses half the range of storage amount of data, unsigned int use all the bits for the magnitude of the number and are positive.


Floating Point Datatype :

Floating Point numbers are stored with 6 digits of precision. Those are defined with keyword float. When the accuracy is not sufficient then the datatype double can be used. double gives a precesion of 14 digits these known as double precesion numbers. Still for a better process we can use long double which uses 80 bits.


Character Datatype :

Character are usually stored in 8 bits


Void datatype :

A void type has no value this is usually used to specify the return type of function , this function does not return any value to calling function


Function returns as void

There are various functions in C which do not return any value or you can say they return void. A function with no return value has the return type as void. For example, void exit (int status);


Function arguments as void

There are various functions in C which do not accept any parameter. A function with no parameter can accept a void. For example, int rand(void);


Pointers to void

A pointer of type void * represents the address of an object, but not its type. For example, a memory allocation function void *malloc(size_t size); returns a pointer to void which can be casted to any data type.


Declaration of Variable :

It tells the complier what the variable name is used, what type of date is held by the variable.

Syn: datetype v1,v2,..vn;
int a,b;
float sum;
double ratio;


Assigning values to variables

Example : 
int x,y;
 x= 10;
 y=5;
 
 Programs : Program for variable declaration
 main( ) 
 { 
 float x,p;
 x=10.1; p=5.2;
 printf ("x = %f", x);
 printf ("p = %f", p);
 }

 Type def program :
 # include 
 main ( ) 
 { 
 typedef int amt ;
 amt Rupees = 20;
 printf ("Rupees %d",Rupees);
 }	

VARIABLES

The name of a variable can be composed of letters, digits, and the underscore character. It must begin with either a letter or an underscore. Upper and lowercase letters are distinct because C is case-sensitive.

Type	Discription

char	Typically a single octet (one byte). This is an integer type.
int	The most natural size of integer for the machine.
float	A single-precision floating point value.
double	A double-precision floating point value.
void	Represents the absence of type.

Variable Declaration in C

A variable declaration is useful when you are using multiple files and you define your variable in one of the files which will be available at the time of linking the program. You will use the keyword extern to declare a variable at any place.

A variable declaration provides assurance to the compiler that there exists a variable with the given type and name so that the compiler can proceed for further compilation without requiring the complete detail about the variable.

#include 
// Variable declaration:
extern int a, b;
extern int c;
extern float f;

int main ()
{
int a, b;
a = 10;
b = 20;
c = a + b;
printf("value of c : %d \n", c);
f = 70.0/3.0;
printf("value of f : %f \n", f);
return 0;
}

L values and R values in C

There are two kinds of expressions in C:


L value :

Expressions that refer to a memory location are called "lvalue" expressions. An lvalue may appear as either the left-hand or right-hand side of an assignment.


R value :

The term rvalue refers to a data value that is stored at some address in memory. An rvalue is an expression that cannot have a value assigned to it which means an rvalue may appear on the right-hand side but not on the left-hand side of an assignment.

Variables are lvalues and so they may appear on the left-hand side of an assignment. Numeric literals are rvalues and so they may not be assigned and cannot appear on the left-hand side.

News Walls


Copyrights © 2016. All Rights Reserved to Learn Computers Home, India. //Site Designed.