Thursday 8 April 2021

DATA TYPE & FORMATS

 

Data type:
          
           Data type are defined as the data storage format that a variable can store a data to perform a specific operation data types are classified into two types.
 (I).  primary data type
(II). secondary data type

(I).Primary data type:
                 
                  In primary there are 5 basic data types. They are int, char, float, double and void.
The storage size and range for int and float
data type will very depend on the CPU processor ( 8, 16, 32 and 64 bit ).



*. Integer data type:
     It allows a variable to store numeric value.  

➡️ "Int" keyword is used to refer integer data                   type.
➡️ Storage size of int data type is 2 or 4 or 8              byte.
➡️ If we use 16 bit processor, 2 byte (16 bit)             memory will be allocated for int data type,
     Similarly, 4 byte of memory for 32 bit                                     processor
                       8 byte of memory for 64 bit
                       processor

*. Character data type:
    It allows a variable to store only one                   character.
➡️  "Char" keyword is used to refer character            data type.
➡️ Storage size of char data type is '1' byte.

*. Floating data type:
                 Floating point data type consists of 2 types.
 (I). Float
(II).Double

(I).Float:
          It allows a variable to store decimal                      values.
➡️ "Float" keyword is used to refer float data            type.
➡️ Strong size of float data type is 4 byte.
➡️ We can use upto 6 digits after decimal using float data type.

FOR EXAMPLE;  10.456789

*. (II).Double:
             "Double" is same as float data type which allows upto 10 digit after decimal.

*. Void data type:
           "Void" is an empty data type that has no value. This can be used in " Function" and "Pointers".

(II). Secondary data type:
                      In secondary data type there are 5 types. They are..
* Array
* Pointers
* Structures
* Unions
* Enumerations
*Array, Pointer, Structure and Union are called drived data type in 'C' language.

Int size range and format:
       Size/range➡️2/ (-32768 to +32768)

Format: (%d)
             It is used to print the signed integer value where signed integer means that the variable can hold both positive and negative values.
                               For %d⬇️


  In the above code, we are printing the integer value of b and c by using the %d specifier.
                           Output⬇️




                           
Format:(%u)
              It is used to print the unsigned integer value where the unsigned integer means that the variable can hold only positive value.
                          For %u⬇️


In the above program, we are displaying the value of b and c by using an unsigned format specifier, i.e., %u. The value of b is positive, so %u specifier prints the exact value of b, but it does not print the value of c as c contains the negative value.
                           Output⬇️




Format:(%o)
               It is used to print the octal unsigned integer where octal integer value always starts with a 0 value.
                           For(%o)⬇️


In the above code, we are displaying the octal value and integer value of a.
                         Output⬇️



Format:(%x)or (%X)
               It is used to print the hexadecimal unsigned integer where the hexadecimal integer value always starts with a 0x value. In this, alphabetical characters are printed in small letters such as a, b, c, etc.
                It is used to print the hexadecimal unsigned integer, but %X prints the alphabetical characters in uppercase such as A, B, C, etc.
                            For(%x)or (%X)⬇️


In the above code, y contains the hexadecimal value 'A'. We display the hexadecimal value of y in two formats. We use %x and %X to print the hexadecimal value where %x displays the value in small letters, i.e., 'a' and %X displays the value in a capital letter, i.e., 'A'.

                              Output⬇️



Format:(%f)
              It is used for printing the decimal floating-point values. By default, it prints the 6 values after '.'.

                              For (%f)⬇️

The above code prints the floating value of y.

                                Output ⬇️



Format:(%e)/(%E)

             It is used for scientific notation. It is also known as Mantissa or Exponent.

                                For(%e)


                                Output⬇️

                                For(%E)⬇️

                               Output⬇️




Format:(%g)

                It is used to print the decimal floating-point values, and it uses the fixed precision, i.e., the value after the decimal in input would be exactly the same as the value in the output.
                                 For(%g)⬇️

 In the above code, we are displaying the floating value of y by using %g specifier. The %g specifier displays the output same as the input with a same precision.                           Output⬇️





Format:(%p)

              It is used to print the address in a hexadecimal form.

                                For(%p)⬇️

                                Output⬇️





Format:(%c)

               It is used to print the unsigned character.

                                 For (%c)⬇️

                                 Output⬇️






Format:(%s)

              It is used to print the strings.

                                For(%s)⬇️

                                 Output⬇️


PROGRAM:

          Write a 'C' program to perform all arithmetic operations.

 

 /**

    * C program to perform all arithmetic                     operations

    */


#include <stdio.h>

int main()

{

    int num1, num2;

    int sum, sub, mult, mod;

    float div;


    /*

     * Input two numbers from user

     */

    printf("Enter any two numbers: ");

    scanf("%d%d", &num1, &num2);


    /*

     * Perform all arithmetic operations

     */ 

    sum = num1 + num2;

    sub = num1 - num2;

    mult = num1 * num2;

    div = (float)num1 / num2;

    mod = num1 % num2;


    /*

     * Print result of all arithmetic operations

     */

    printf("SUM = %d\n", sum);

    printf("DIFFERENCE = %d\n", sub);

    printf("PRODUCT = %d\n", mult);

    printf("QUOTIENT = %f\n", div);

    printf("MODULUS = %d", mod);


    return 0; 

}


Hindi Translation: เคนिंเคฆी เค…เคจुเคตाเคฆ:⬇️⬇️๐Ÿ‘‡


Data type:

           Data type เค•ो data storage format เค•े เคฐूเคช เคฎें เคชเคฐिเคญाเคทिเคค เค•िเคฏा เคœाเคคा เคนै เคœो เคเค• variable เค•िเคธी เคตिเคถेเคท เค‘เคชเคฐेเคถเคจ(specific operation) เค•ो เค•เคฐเคจे เค•े เคฒिเค data เค•ो store เค•เคฐ เคธเค•เคคा เคนै, Data type เค•ो เคฆो เคช्เคฐเค•ाเคฐों เคฎें เคตเคฐ्เค—ीเค•ृเคค(classified) เค•िเคฏा เคœाเคคा เคนै।

 (I). primary data type

(II). secondary data type


 (I). primary data type:

                        เคช्เคฐाเคฅเคฎिเค• เคฎें 5 basic data types  เคนैं। เคตे int, char, float, double เค”เคฐ void เคนैं।

 Int เค”เคฐ float เค•े เคฒिเค storage size เค”เคฐ range

 Data type เคฌเคนुเคค CPU เคช्เคฐोเคธेเคธเคฐ (8, 16, 32 เค”เคฐ 64 bit) เคชเคฐ เคจिเคฐ्เคญเคฐ เค•เคฐेเค—ा। 


*. Integer data type:

                    เคฏเคน เคเค• variable เค•ो numeric value เค•ो store เค•เคฐเคจे เค•ी เค…เคจुเคฎเคคि เคฆेเคคा เคนै। 

➡️ Data "Int" keyword เค•ा เค‰เคชเคฏोเค—                   integer data type เค•ो เคธंเคฆเคฐ्เคญिเคค เค•เคฐเคจे เค•े เคฒिเค เค•िเคฏा เคœाเคคा เคนै।

➡️ Type int data type เค•ा storage size 2 เคฏा 4 เคฏा 8 byte เคนोเคคा เคนै।

➡️ เคฏเคฆि เคนเคฎ 16 เคฌिเคŸ เคช्เคฐोเคธेเคธเคฐ เค•ा เค‰เคชเคฏोเค— เค•เคฐเคคे เคนैं,  เคคो 2 เคฌाเค‡เคŸ (16 เคฌिเคŸ) เคฎेเคฎोเคฐी เค•ो int data type   เค•े เคฒिเค allocated เค•िเคฏा เคœाเคเค—ा,

เค‡เคธी เคคเคฐเคน, 32 เคฌिเคŸ เคช्เคฐोเคธेเคธเคฐ เค•े เคฒिเค 4 เคฌाเค‡เคŸ เคฎेเคฎोเคฐी

 64 เคฌिเคŸ เค•े เคฒिเค 8 เคฌाเค‡เคŸ เคฎेเคฎोเคฐी เคช्เคฐोเคธेเคธเคฐ


*. Character data type:

 เคฏเคน เค•ेเคตเคฒ เคเค• เคตเคฐ्เคฃ เค•ो เคธंเค—्เคฐเคนीเคค เค•เคฐเคจे เค•े เคฒिเค เคเค• character เค•ी เค…เคจुเคฎเคคि เคฆेเคคा เคนै।

 ➡️ "Char" keyword เค•ा เค‰เคชเคฏोเค— character data                type เค•ो เคธंเคฆเคฐ्เคญिเคค เค•เคฐเคจे เค•े เคฒिเค เค•िเคฏा เคœाเคคा เคนै।

       Type character data type เค•ा storage size '1'          byte เคนै।


 *. Floating data type:

             Floating point data type เคฎें 2 เคช्เคฐเค•ाเคฐ เคนोเคคे เคนैं।

 (1). Float

 (II). Double


 (I). Float:

 เคฏเคน เคเค• เคšเคฐ เค•ो เคฆเคถเคฎเคฒเคต เคฎाเคจों เค•ो เคธंเค—्เคฐเคนीเคค เค•เคฐเคจे เค•ी เค…เคจुเคฎเคคि เคฆेเคคा เคนै।

 । "เคซ्เคฒोเคŸ" เค•ीเคตเคฐ्เคก เค•ा เค‰เคชเคฏोเค— เคซ्เคฒोเคŸ เคกेเคŸा เคช्เคฐเค•ाเคฐ เค•ो เคธंเคฆเคฐ्เคญिเคค เค•เคฐเคจे เค•े เคฒिเค เค•िเคฏा เคœाเคคा เคนै।

 เคซ्เคฒोเคŸ เคกेเคŸा เคช्เคฐเค•ाเคฐ เค•ा เคฎเคœเคฌूเคค เค†เค•ाเคฐ 4 เคฌाเค‡เคŸ เคนै।

 ➡️ เคนเคฎ เคซ्เคฒोเคŸ เคกेเคŸा เคช्เคฐเค•ाเคฐ เค•ा เค‰เคชเคฏोเค— เค•เคฐเค•े เคฆเคถเคฎเคฒเคต เค•े เคฌाเคฆ 6 เค…ंเค•ों เคคเค• เค•ा เค‰เคชเคฏोเค— เค•เคฐ เคธเค•เคคे เคนैं।


 เค‰เคฆाเคนเคฐเคฃ เค•े เคฒिเค; 10.456789


 *.(II) Double:

 "เคกเคฌเคฒ" เคซ्เคฒोเคŸ เคกेเคŸा เคช्เคฐเค•ाเคฐ เค•े เคธเคฎाเคจ เคนै เคœो เคฆเคถเคฎเคฒเคต เค•े เคฌाเคฆ 10 เค…ंเค•ों เคคเค• เค•ी เค…เคจुเคฎเคคि เคฆेเคคा เคนै।


 *. Void data type:

              "Void" เคเค• empty data type เคนै เคœिเคธเค•ा เค•ोเคˆ เคฎूเคฒ्เคฏ(value) เคจเคนीं เคนै। เค‡เคธเค•ा เค‰เคชเคฏोเค— "Function" เค”เคฐ "Pointers" เคฎें เค•िเคฏा เคœा เคธเค•เคคा เคนै।


 (II). Secondary data type:

         Secondary data type เคฎें 5 เคช्เคฐเค•ाเคฐ เคนोเคคे เคนैं। เคตो เคนैं..

 * Array

 * Pointer

 * Structure

 * Union

 * Enumeration

 * Array, pointer, structure เค”เคฐ Union เค•ो 'C' เคฒैंเค—्เคตेเคœ เคฎें drived data type เค•เคนा เคœाเคคा เคนै।


Int size range เค”เคฐ range:

 Size/ range +2 / (-32768 เคธे +32768)


 Format: (% d)

 เค‡เคธเค•ा เค‰เคชเคฏोเค— เคนเคธ्เคคाเค•्เคทเคฐिเคค integer value เค•ो print เค•เคฐเคจे เค•े เคฒिเค เค•िเคฏा เคœाเคคा เคนै เคœเคนां เคนเคธ्เคคाเค•्เคทเคฐ เค•िเค เค—เค integer เค•ा เค…เคฐ्เคฅ เคนै เค•ि variable เคธเค•ाเคฐाเคค्เคฎเค• เค”เคฐ เคจเค•ाเคฐाเคค्เคฎเค• เคฆोเคจों เคฎाเคจों เค•ो เคงाเคฐเคฃ เค•เคฐ เคธเค•เคคा เคนै।

                        % D⬇️ เค•े เคฒिเค

     เค‰เคชเคฐोเค•्เคค เค•ोเคก เคฎें, เคนเคฎ% d specifier เค•ा เค‰เคชเคฏोเค— เค•เคฐเค•े b เค”เคฐ c เค•े integer value เค•ो เคช्เคฐिंเคŸ เค•เคฐ เคฐเคนे เคนैं।

                                Output⬇️




Format:(%u)

              เค‡เคธเค•ा เค‰เคชเคฏोเค— เค…เคนเคธ्เคคाเค•्เคทเคฐिเคค integer value  เค•ो print เค•เคฐเคจे เค•े เคฒिเค เค•िเคฏा เคœाเคคा เคนै เคœเคนां เค…เคนเคธ्เคคाเค•्เคทเคฐिเคค integer เค•ा เค…เคฐ्เคฅ เคนै เค•ि variable เค•ेเคตเคฒ เคธเค•ाเคฐाเคค्เคฎเค• เคฎाเคจ เคฐเค– เคธเค•เคคा เคนै।

                           %u⬇️ เค•े เคฒिเค

     เค‰เคชเคฐोเค•्เคค program เคฎें, เคนเคฎ เค…เคนเคธ्เคคाเค•्เคทเคฐिเคค เคช्เคฐाเคฐूเคช เคตिเคจिเคฐ्เคฆेเคถเค•, เค…เคฐ्เคฅाเคค,% u เค•ा เค‰เคชเคฏोเค— เค•เคฐเค•े b เค”เคฐ c เค•ा เคฎाเคจ เคช्เคฐเคฆเคฐ्เคถिเคค เค•เคฐ เคฐเคนे เคนैं। B เค•ा เคฎाเคจ เคงเคจाเคค्เคฎเค• เคนै, เค‡เคธเคฒिเค% u specifier b เค•े เคธเคŸीเค• เคฎाเคจ เค•ो เคช्เคฐिंเคŸ เค•เคฐเคคा เคนै, เคฒेเค•िเคจ เคฏเคน c เค•े เคฎाเคจ เค•ो เคช्เคฐिंเคŸ เคจเคนीं เค•เคฐเคคा เคนै เค•्เคฏोंเค•ि c เคฎें เค‹เคฃाเคค्เคฎเค• เคฎाเคจ เคนोเคคा เคนै।  

                             Output⬇️





Format: (% o)

               เค‡เคธเค•ा เค‰เคชเคฏोเค— octal เค…เคนเคธ्เคคाเค•्เคทเคฐिเคค integer เค•ो เคช्เคฐिंเคŸ เค•เคฐเคจे เค•े เคฒिเค เค•िเคฏा เคœाเคคा เคนै เคœเคนां octal integer value เคนเคฎेเคถा 0 เคฎाเคจ เคธे เคถुเคฐू เคนोเคคा เคนै।

                       (% o) เค•े เคฒिเค⬇️

เค‰เคชเคฐोเค•्เคค เค•ोเคก เคฎें, เคนเคฎ octal value เค”เคฐ integer value เค•ो เคช्เคฐเคฆเคฐ्เคถिเคค เค•เคฐ เคฐเคนे เคนैं।

                             Output⬇️




Format:(%x)or (%X)

               เค‡เคธเค•ा เค‰เคชเคฏोเค— เคนेเค•्เคธाเคกेเคธिเคฎเคฒ เค…เคนเคธ्เคคाเค•्เคทเคฐिเคค integer เค•ो เคช्เคฐिंเคŸ เค•เคฐเคจे เค•े เคฒिเค เค•िเคฏा เคœाเคคा เคนै เคœเคนां เคนेเค•्เคธाเคกेเคธिเคฎเคฒ Integer เคฎाเคจ เคนเคฎेเคถा 0x เคฎाเคจ เคธे เคถुเคฐू เคนोเคคा เคนै। เค‡เคธเคฎें alphabetical เค•े เค…เค•्เคทเคฐ เค›ोเคŸे เค…เค•्เคทเคฐों เคฎें Print เคนोเคคे เคนैं เคœैเคธे a, b, c, เค†เคฆि।

เค‡เคธเค•ा เค‰เคชเคฏोเค— เคนेเค•्เคธाเคกेเคธिเคฎเคฒ เค…เคนเคธ्เคคाเค•्เคทเคฐिเคค integer เค•ो เคช्เคฐिंเคŸ เค•เคฐเคจे เค•े เคฒिเค เค•िเคฏा เคœाเคคा เคนै, เคฒेเค•िเคจ% X เค…เคชเคฐเค•ेเคธ เคฎें เคตเคฐ्เคฃเคฎाเคฒा เคตเคฐ्เคฃों เค•ो เคช्เคฐिंเคŸ เค•เคฐเคคा เคนै เคœैเคธे A, B, C, เค†เคฆि।

                     (%x)or (%X) เค•े  เคฒिเค⬇️

เค‰เคชเคฐोเค•्เคค เค•ोเคก เคฎें, y เคฎें เคนेเค•्เคธाเคกेเคธिเคฎเคฒ เคฎाเคจ 'A' เคนै। เคนเคฎ เคฆो format เคฎें y เค•ा เคนेเค•्เคธाเคกेเคธिเคฎเคฒ เคฎाเคจ เคช्เคฐเคฆเคฐ्เคถिเคค เค•เคฐเคคे เคนैं। เคนเคฎ เคนेเค•्เคธाเคกेเคธिเคฎเคฒ เคฎाเคจ เค•ो print เค•เคฐเคจे เค•े เคฒिเค% x เค”เคฐ% X เค•ा เค‰เคชเคฏोเค— เค•เคฐเคคे เคนैं เคœเคนां% x เค›ोเคŸे เค…เค•्เคทเคฐों เคฎें เคฎूเคฒ्เคฏ เคช्เคฐเคฆเคฐ्เคถिเคค เค•เคฐเคคा เคนै, เค…เคฐ्เคฅाเคค, 'a' เค”เคฐ% X เคเค• เคฌเคก़े เค…เค•्เคทเคฐ เคฎें เคฎाเคจ เคช्เคฐเคฆเคฐ्เคถिเคค เค•เคฐเคคा เคนै, เค…เคฐ्เคฅाเคค 'A'.

                               Output ⬇️





Format: (% f)

 เคฏเคน เคฆเคถเคฎเคฒเคต เคซ्เคฒोเคŸिंเค—-เคชॉเค‡ंเคŸ เคฎाเคจों เค•ो เคช्เคฐिंเคŸ เค•เคฐเคจे เค•े เคฒिเค เค‰เคชเคฏोเค— เค•िเคฏा เคœाเคคा เคนै। เคกिเคซ़ॉเคฒ्เคŸ เคฐूเคช เคธे, เคฏเคน '।' เค•े เคฌाเคฆ 6 เคฎाเคจ เคช्เคฐिंเคŸ เค•เคฐเคคा เคนै।

                      (% F) ⬇️ เค•े เคฒिเค


เค‰เคชเคฐोเค•्เคค เค•ोเคก y เค•े เค…เคธ्เคฅाเคฏी เคฎाเคจ เค•ो เคช्เคฐिंเคŸ เค•เคฐเคคा เคนै।

                        Output⬇️





Format:(e)/(%E)

เค‡เคธเค•ा เค‰เคชเคฏोเค— เคตैเคœ्เคžाเคจिเค• เคธंเค•ेเคคเคจ เค•े เคฒिเค เค•िเคฏा เคœाเคคा เคนै। เค‡เคธे เคฎंเคŸिเคธा เคฏा เคเค•्เคธเคชोเคจेंเคŸ เค•े เคฐूเคช เคฎें เคญी เค•िเคฏा เคœाเคคा เคนै 

                             (%e)เค•े เคฒिเค


                                Output⬇️


                            (%E) เค•े เคฒिเค⬇️

                                Output⬇️





Format: (% g)

เค‡เคธเค•ा เค‰เคชเคฏोเค— เคฆเคถเคฎเคฒเคต เคซ्เคฒोเคŸिंเค—-เคชॉเค‡ंเคŸ เคฎाเคจों เค•ो เคช्เคฐिंเคŸ เค•เคฐเคจे เค•े เคฒिเค เค•िเคฏा เคœाเคคा เคนै, เค”เคฐ เคฏเคน เคจिเคถ्เคšिเคค เคชเคฐिเคถुเคฆ्เคงเคคा เค•ा เค‰เคชเคฏोเค— เค•เคฐเคคा เคนै, เค…เคฐ्เคฅाเคค, เค‡เคจเคชुเคŸ เค•े เคฆเคถเคฎเคฒเคต เค•े เคฌाเคฆ เค•ा เคฎूเคฒ्เคฏ เค†เค‰เคŸเคชुเคŸ เคฎें เคฎूเคฒ्เคฏ เค•े เคธเคฎाเคจ เคนी เคนोเค—ा।

                           (% g) เค•े เคฒिเค⬇️


เค‰เคชเคฐोเค•्เคค เค•ोเคก เคฎें, เคนเคฎ% g specifier เค•ा เค‰เคชเคฏोเค— เค•เคฐเค•े y เค•े เค…เคธ्เคฅाเคฏी เคฎाเคจ เค•ो เคช्เคฐเคฆเคฐ्เคถिเคค เค•เคฐ เคฐเคนे เคนैं।  % G specifier เค†เค‰เคŸเคชुเคŸ เค•ो เค‰เคธी เคชเคฐिเคถुเคฆ्เคงเคคा เค•े เคธाเคฅ เค‡เคจเคชुเคŸ เค•े เคฐूเคช เคฎें เคช्เคฐเคฆเคฐ्เคถिเคค เค•เคฐเคคा เคนै। 

                                Output⬇️




Format: (% p)

เค‡เคธเค•ा เค‰เคชเคฏोเค— เคชเคคे เค•ो เคนेเค•्เคธाเคกेเคธिเคฎเคฒ เคฐूเคช เคฎें เคช्เคฐिंเคŸ เค•เคฐเคจे เค•े เคฒिเค เค•िเคฏा เคœाเคคा เคนै।

                        (% p) เค•े เคฒिเค ⬇️

                                Output⬇️






Format: (% c)

เค‡เคธเค•ा เค‰เคชเคฏोเค— เค…เคนเคธ्เคคाเค•्เคทเคฐिเคค เคตเคฐ्เคฃ เค•ो เคช्เคฐिंเคŸ เค•เคฐเคจे เค•े เคฒिเค เค•िเคฏा เคœाเคคा เคนै।

                          (% c) เค•े เคฒिเค ⬇️

                                Output⬇️


         




Format: (% s)

 เค‡เคธเค•ा เค‰เคชเคฏोเค— เคธ्เคŸ्เคฐिंเค—्เคธ เค•ो เคช्เคฐिंเคŸ เค•เคฐเคจे เค•े เคฒिเค เค•िเคฏा เคœाเคคा เคนै।

                        (% s)เค•े เคฒिเค ⬇️

                                Output⬇️



PROGRAM:

              เคธเคญी เค…ंเค•เค—เคฃिเคคीเคฏ เค‘เคชเคฐेเคถเคจ เค•เคฐเคจे เค•े เคฒिเค เคเค• 'C' เคช्เคฐोเค—्เคฐाเคฎ เคฒिเค–ें।


 /**

    * C program to perform all arithmetic                     operations

    */


#include <stdio.h>

int main()

{


    int num1, num2;

    int sum, sub, mult, mod;

    float div;


    /*

     * Input two numbers from user

     */


    printf("Enter any two numbers: ");

    scanf("%d%d", &num1, &num2);


    /*

     * Perform all arithmetic operations

     */ 


    sum = num1 + num2;

    sub = num1 - num2;

    mult = num1 * num2;

    div = (float)num1 / num2;

    mod = num1 % num2;



   /*

    * Print result of all arithmetic operations

    */


    printf("SUM = %d\n", sum);

    printf("DIFFERENCE = %d\n", sub);

    printf("PRODUCT = %d\n", mult);

    printf("QUOTIENT = %f\n", div);

    printf("MODULUS = %d", mod);


    return 0; 


}

OPERATOR IN C

  Operators : An operator is the symbol that specify the operation or activity to be perform. Example :                  C language is ve...