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; 


}

10 comments:

OPERATOR IN C

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