Computer Concept & Programming In C - Unit II - 3

Q.4 Explain different data types in C.
Related Questions -
Q. Write the various data type.                                 (AKTU. 2008 - 09) 
Ans. (i) Character Type (The char Data Type): -


An object of the char data type represents a single character of the character set used by your computer. For example A, B, a, b are characters but 7 is a number. But a 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. Usually a character takes 8 bits i.e. 1 byte to store its numeric code.
For many computers, the ASCII codes are the our standard codes to represent a character set. ASCII stands for (American Standard Code for Information Interchange). The original ASCII character set has only 128 characters because it uses the lower 7 bits that can represent 27 (that is 128) characters.
Character Variables: -
A variable that can represent different characters is called a character variable.
One can set the data type of a variable to char. by using the following declaration format.
char variable name;
Where variable name is the place where you put the name of a variable.
If more than one variable to be declared can be used the following format.
char <variable name 1>;
char <variable name 2>;
char <variable name 3>;
char <variable name />;
Alternative way.
char variable name 1, variable name 2, variable name 3;
Character constants: -
A character enclosed in a single quotes is called a character constant. For instance, ‘A’, ‘a’, ‘B’ and ‘b’ are all character constants that have their unique numeric values in the ASCII character set.
Given x as a character variable, the following two assignment statements are equivalent. x = ‘A’; and x = 65; 
The Escape character (\): -
In C language (\) backslash is called the escape character it tells the computer that a special character follows.
For instance, when the computer see (\) in the new line character \n, it knows that the next character causes a sequence of a carriage return and a line feed.
Besides, the newline character, several other characters exists in C language, such as the following.
Character Description
     \b The backspace character; moves the cursor to the left one character.
     \f The formfeed character; goes to the top of a new page.
     \r The return character; returns to the beginning of the current line.
     \t The tab character; advances to the next tab stop.
Print Out Characters: -
The printf ( ) function defined in the C header file <stdio.h> can be used to print out messages on the screen. We use the character format specifier %c which indicates to the printf ( ) function that the argument to be printed is a character.
A program to print out characters on the screen.
# include <stdio.h>
# include <conio.h>
void main ( )
  {
      char C1;
      char C2;
      C1 = ‘A’;
      C2 = ‘a’;
       printf (“Convert the value of C1 to character: %c.\n,” C1);
       printf (“Convert the value of C2 to character: %c.\n,” C2);
       getch ( );
   }
The output for above program is:
Convert the value of C1 to character: A.
Convert the value of C1 to character: a.
Converting the numeric values back to characters: -
   # include <stdio.h>
   # include < conio.h>
   void main ( )
     {
        char C1;
        char C2;
        C1 = 65;
        C2 = 97;
printf (“The character that has the numeric value of 65 is: %c.\n”, C1);
printf (“The character that has the numeric value of 97 is: %c.\n”, C2);
getch ( );
      }
The output of program is:
The character that has the numeric value of 65 is: A.
The character that has the numeric value of 97 is a.
(ii) Integer Types (The int data Type): -
The int keyword is used to specify the type of a variable as an integer. Integer numbers are also called whole numbers, which have no fractional part or decimal part. Therefore the result of an integer division is truncated simply because any fraction part is ignored.
Declaring Integer Variables: -
The Following is the basic declaration format.
int <variable name>;
similar to the character declaration if more than one variable are to be declare can be used the following format.
int <variable name 1>;
int <variable name 2>;
int <variable name 3>;
Alternative way. 
int variable name 1, variable name 2, variable name 3;
Here <variable name 1>, <variable name 2> and <variable name 3> are places where you put the name of int variables.