{"id":398,"date":"2020-12-31T05:37:16","date_gmt":"2020-12-31T05:37:16","guid":{"rendered":"https:\/\/usemynotes.com\/?p=398"},"modified":"2023-02-14T16:51:20","modified_gmt":"2023-02-14T16:51:20","slug":"data-types-in-c-programming","status":"publish","type":"post","link":"https:\/\/usemynotes.com\/data-types-in-c-programming\/","title":{"rendered":"Data Types in C Programming"},"content":{"rendered":"<p>Glad to see all of you, here again, Welcome again folks, in this module, we are going to talk about Data Types in <a href=\"https:\/\/usemynotes.com\/c-programming\/\">C Programming<\/a>, till now we have completed a wonderful journey in this series and also are ready to go ahead.<\/p>\n<p>Let\u2019s start this module and look into details about the same.<\/p>\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_80 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 eztoc-toggle-hide-by-default' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/usemynotes.com\/data-types-in-c-programming\/#Data_Types_in_C_Programming\" >Data Types in C Programming<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/usemynotes.com\/data-types-in-c-programming\/#About_Data_types_in_C_Programming\" >About Data types in C Programming<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/usemynotes.com\/data-types-in-c-programming\/#Primary_Data_Types_in_C_programming\" >Primary Data Types in C programming<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/usemynotes.com\/data-types-in-c-programming\/#int_data_types_in_C_Programming\" >int data types in C Programming<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/usemynotes.com\/data-types-in-c-programming\/#char_data_types_in_C_Programming\" >char data types in C Programming<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/usemynotes.com\/data-types-in-c-programming\/#bool_data_types_in_C_Programming\" >bool data types in C Programming<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/usemynotes.com\/data-types-in-c-programming\/#float_data_types_in_C_Programming\" >float data types in C Programming<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/usemynotes.com\/data-types-in-c-programming\/#double_data_types_in_C_Programming\" >double data types in C Programming<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/usemynotes.com\/data-types-in-c-programming\/#User-defined_Data_types_in_C_Programming\" >User-defined Data types in C Programming<\/a><\/li><\/ul><\/nav><\/div>\n<h2><span class=\"ez-toc-section\" id=\"Data_Types_in_C_Programming\"><\/span>Data Types in C Programming<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><img decoding=\"async\" class=\"alignnone wp-image-400 size-full\" src=\"https:\/\/usemynotes.com\/wp-content\/uploads\/2020\/12\/data-types-in-c-programming.jpg\" alt=\"Data types in C Programming\" width=\"1008\" height=\"702\" title=\"\" srcset=\"https:\/\/usemynotes.com\/wp-content\/uploads\/2020\/12\/data-types-in-c-programming.jpg 1008w, https:\/\/usemynotes.com\/wp-content\/uploads\/2020\/12\/data-types-in-c-programming-300x209.jpg 300w, https:\/\/usemynotes.com\/wp-content\/uploads\/2020\/12\/data-types-in-c-programming-768x535.jpg 768w, https:\/\/usemynotes.com\/wp-content\/uploads\/2020\/12\/data-types-in-c-programming-150x104.jpg 150w, https:\/\/usemynotes.com\/wp-content\/uploads\/2020\/12\/data-types-in-c-programming-696x485.jpg 696w, https:\/\/usemynotes.com\/wp-content\/uploads\/2020\/12\/data-types-in-c-programming-603x420.jpg 603w, https:\/\/usemynotes.com\/wp-content\/uploads\/2020\/12\/data-types-in-c-programming-100x70.jpg 100w\" sizes=\"(max-width: 1008px) 100vw, 1008px\" \/><\/p>\n<p>We talked about <a href=\"https:\/\/usemynotes.com\/variables-and-constants-in-c-programming\/\">variables and constants<\/a> in the last module and there we were using data type also while declaring a variable and constant, if you haven\u2019t seen the last module yet, then I Will recommend you to first go through the last module and then come into this module.<\/p>\n<p><strong>Data types in C Programming<\/strong> talk about the type and nature of the value that a particular variable is going to hold. i.e., suppose you buy water from a store, now the water bottle is the container i.e., the variable and the brand of water or the liquidity nature of the water is the data type here. In simple we should know what is nature and the type of things that are being stored in the container or variable in programming.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"About_Data_types_in_C_Programming\"><\/span>About Data types in C Programming<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Data types in C Programming define the specific type of data that a particular variable can hold, for example, an integer variable can hold integer data, a character type variable can hold character data, a floating-point variable can hold decimal data, etc.<\/p>\n<p><strong>Data Types in C Programming<\/strong> are categorized into mainly 3 groups<\/p>\n<ul>\n<li>User-defined Data Types in C Programming<\/li>\n<li>Built-in \/ Primary Data Types in C Programming<\/li>\n<li>derived Data Types in C Programming<\/li>\n<\/ul>\n<p>Primary data types in C programming include Integer, Character, Boolean, Floating-Point i.e., decimal value, Double Floating Point i.e., large values, void i.e., null value, and wide character.<\/p>\n<p><strong>Derived data types<\/strong> include Function, Array, Pointer, and references.<\/p>\n<p><strong>User-defined data types <\/strong>include class, structure, union, enum, and typedef.<\/p>\n<p>In this particular module, we will talk about primary data types in detail and the rest we will cover in the upcoming modules.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Primary_Data_Types_in_C_programming\"><\/span>Primary Data Types in C programming<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Primary data types are also called built-in data types, i.e., they are already built and stored in the C library. Let\u2019s see the function of different built-in data types available:<\/p>\n<h3><span class=\"ez-toc-section\" id=\"int_data_types_in_C_Programming\"><\/span>int data types in C Programming<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>It is for integers it takes up to 2 or 4 bytes of memory from the compiler (1 byte = 8 bits) and can only store the integer values like 10, 20, and so on.<br \/>\nExample, int num = 20 ;<\/p>\n<h3><span class=\"ez-toc-section\" id=\"char_data_types_in_C_Programming\"><\/span>char data types in C Programming<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>It is for storing a character and takes up to 1 byte of memory from the compiler.<\/p>\n<p>For example, char ch = \u2018A\u2019;<\/p>\n<p>Here, in this example, char is the data type and ch is the variable name, which has stored the character A in it. One thing to be noted in this case is that while assigning a character to any variable, it should be in single quotation marks as given in the above example, else it will throw an error.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"bool_data_types_in_C_Programming\"><\/span>bool data types in C Programming<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>It is for Booleans True or False (0 or 1). It is used for checking various conditions required in the program, will see about this in the later modules.<\/p>\n<p>For example, bool b = true;<\/p>\n<h3><span class=\"ez-toc-section\" id=\"float_data_types_in_C_Programming\"><\/span>float data types in C Programming<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>it is used for storing a floating-point number, i.e., a decimal number and takes up to 4 bytes of memory from the compiler.<\/p>\n<p>Example, float num = 12.23 ;<\/p>\n<p>Here, in this example, num is the variable name that is assigned with float data type and is holding a 12.23 value in it.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"double_data_types_in_C_Programming\"><\/span>double data types in C Programming<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>It is used to store a large value decimal number and it takes up to 8 bytes of memory.<\/p>\n<p>Example, double num = 10078.10099 ;<\/p>\n<p>Here, if you have to store a large number then you have to go for the double data type.<\/p>\n<p>Let\u2019s see one sample problem demonstrating the data types.<\/p>\n<pre class=\"brush: cpp; title: ; notranslate\" title=\"\">#include &lt;stdio.h&gt;\r\nint main( ) {\r\nint n1 = 20;\r\nfloat n2 = 45.3;\r\nchar chr = \u2018A\u2019;\r\n\r\n\/\/ Displaying the value of variable n1\r\nprintf (\u201c n1: %d\u201c, n1);\r\n\r\n\/\/ Displaying the value of variable n2\r\nprintf (\u201c n2: %f\u201d, n2);\r\n\r\n\/\/ Displaying the value of variable chr\r\nprintf (\u201cchr: %c\u201c, chr);\r\n\r\nreturn 0;\r\n}<\/pre>\n<p>The <strong>output<\/strong> of the above Program:<\/p>\n<table>\n<tbody>\n<tr>\n<td>n1: 20<br \/>\nn2: 45.3<br \/>\nchr: A<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Here, in the above program, we have declared 3 types of data types int, float, and char with the n1, n2, and chr variables respectively and thus printing the same with printf() function. Different data types use different format specifiers, we have discussed format specifiers in the last module refer to that if we haven&#8217;t.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"User-defined_Data_types_in_C_Programming\"><\/span>User-defined Data types in C Programming<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>There were some data types that were not defined in the C library, but there was a need for that, so in this, we the user can define our own data type, which is also known as secondary or non-primitive data type. Users can define this as per their requirements. There are many types of user-defined data types such as <a href=\"https:\/\/usemynotes.com\/what-are-arrays-in-c-programming\/\">arrays<\/a>, <a href=\"https:\/\/usemynotes.com\/what-are-pointers-in-c-programming\/\">pointers<\/a>, <a href=\"https:\/\/usemynotes.com\/what-are-structures-in-c-programming\/\">structures<\/a>, <a href=\"https:\/\/usemynotes.com\/what-is-union-in-c-programming\/\">unions<\/a>, functions, etc. We will talk about this in more detail in the upcoming modules. so stay tuned.<\/p>\n<p>In the <strong>Data Types in C Programming<\/strong> module, we have discussed one of the most important concepts of the C programming series i.e., data types. Hope you all are enjoying the programming and are excited about the upcoming modules.<\/p>\n<p>Until then, Stay connected, keep learning, and have Happy coding!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Glad to see all of you, here again, Welcome again folks, in this module, we are going to talk about Data Types in C Programming, till now we have completed a wonderful journey in this series and also are ready to go ahead. Let\u2019s start this module and look into details about the same. Data [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":400,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[],"class_list":{"0":"post-398","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-c-programming"},"_links":{"self":[{"href":"https:\/\/usemynotes.com\/wp-json\/wp\/v2\/posts\/398","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/usemynotes.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/usemynotes.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/usemynotes.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/usemynotes.com\/wp-json\/wp\/v2\/comments?post=398"}],"version-history":[{"count":0,"href":"https:\/\/usemynotes.com\/wp-json\/wp\/v2\/posts\/398\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/usemynotes.com\/wp-json\/wp\/v2\/media\/400"}],"wp:attachment":[{"href":"https:\/\/usemynotes.com\/wp-json\/wp\/v2\/media?parent=398"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/usemynotes.com\/wp-json\/wp\/v2\/categories?post=398"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/usemynotes.com\/wp-json\/wp\/v2\/tags?post=398"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}