Initialization of all Datatypes (int, char, float, double)

Program:

#include<stdio.h>
#include<conio.h>
void main()
{
    int n=100;
    char ch='L';
    float ft=20.15;
    double db=1274.1485;
    clrscr();
    printf("n=%d", n);
    printf("\nch=%c", ch);
    printf("\nft=%f", ft);
    printf("\ndb=%lf", db);
    getch();
}


Output:
n=100
ch=L
ft=20.148000
db=1274.148500


Note:

                    Floating (float, double and longdouble) values displays 6 digits after the decimal point, by default.
                    If we want to display specified number of digits after decimal point for floating values, we use some technique i.e., See the next program.......    Specified Number of Decimal Points for floating Values

Definitions :

#include<stdio.h> :

                It is a preprocessor file which include the header file of stdio.h(standard input output ) header file. In these header file contains the functions of printf(), scanf(), etc.,

#include<conio.h> :

                It is a preprocessor file which include the header file of conio.h(console input output ) header file. In these header file contains the functions like clrscr(), getch(), etc.,

void main(){} :

                In these Main function we can write our entire program with statements.

                void => It tell is an Empty argument

printf   :      

   It is a function and is  used to print data on the standard output device (monitor).

int : 

It is positive, negative and whole values but not a decimal number.
        Eg: 10, 20, 45,-30, 0 etc.

char : 

A single character can be treated as character data type and it is defined between single quotation marks.
         Eg: ‘r’, ‘H’, ‘5’, ‘*’, etc. 
    Note: String is also a character data type. A group of characters defined between double quotation marks is a String.
   Eg:  “HHHH”, “abc985”,"123*/&", etc.

float : 

The numbers which are stored in the form of floating point representation is called
 as float data type.
     Eg: 10.25, 478.1234, -56.37821, etc.

double : 

The numbers which are stored in the form of double precision floating point representation is called as double data type.
      Eg: 1023.56789, 12345.3672, 0.456321, -567.4556 etc.
Note :
           void :   Empty Data type

clrscr() :

                This function clears the console screen of any previous outputs so that the output of the program currently executed alone is visible on the console screen.

getch() :

                 The function getch() basically stands for "get character". The getch() function is usually used to hold the output screen until the user presses on the keyboard i.e., the case of pressing key to continue.


No comments:

Post a Comment