Thursday, August 30, 2012

Data types and names in c

The char data type: An object of char data type represents a single character e.g a, b, d, A, F, D, 5,9 &,%,( etc.
computer can only store numeric code, therefore characters such as A, a, B, b and so on all have a unique numeric code that is used by computers to represent the characters. For many computers, the ASCII codes are the standard code that is used by the computer to represent a character set.

Character Variable: A variable that can represent different characters is called the character variable.
e.g char sann;
or char sann, s1, s2, stdnt; (you can define more than one characters in single line as shown here).

To print a character we use character format specifier %c, which indicates to printf() function that the argument to be printed is a character.

void main()
char c1='a';
char c2='5';
printf("output: %c",c1);
printf("output: %c",c2 );

The int data type: The int keyword is used to specify the type of a variable as an integer. Integer numbers are also called the whole numbers.

Declaring integer variables:
int variablename;(basic declaration format).
or int variablename1, variablename2, variablename3;

int type:

type                    size(byte)               minimum value               maximum value           format specifer

short int                 2                            -2^15                             2^15-1                       %hd
int                         2                            -2^15                             2^15-1                        %d
long int                  4                            -2^31                             2^31-1                        %ld
long long int           8                            -2^63                             2^63-1                        %lld

Real numbers: The real type holds the values that consists of an integral part and fractional part such as 56.908. there are three different size of real types.
(i) float (4 byes, %f, precision 6 digits) (ii) double (10 bytes, %f, precision 10 digits) (iii) long double (10 bytes, %Lf, precision 10 digits).

variable declaration:
float price;
long double radius;
double a;

No comments:

Post a Comment