{"id":63,"date":"2026-05-19T14:50:18","date_gmt":"2026-05-19T14:50:18","guid":{"rendered":"https:\/\/gigz.pk\/cpp\/?post_type=lesson&#038;p=63"},"modified":"2026-05-22T06:21:16","modified_gmt":"2026-05-22T06:21:16","slug":"data-types","status":"publish","type":"lesson","link":"https:\/\/gigz.pk\/cpp\/?lesson=data-types","title":{"rendered":"Data Types"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Data types in C++ define the type of data a variable can store. They help the compiler understand how much memory to allocate and what kind of operations can be performed on the data.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What are Data Types?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">A data type specifies:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The kind of value a variable can hold<\/li>\n\n\n\n<li>The size of memory required<\/li>\n\n\n\n<li>The operations allowed on that data<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>int age = 18;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Here, <code>int<\/code> is the data type.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Types of Data Types in C++<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">C++ data types are mainly divided into:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Basic (Primitive) Data Types<\/li>\n\n\n\n<li>Derived Data Types<\/li>\n\n\n\n<li>User-Defined Data Types<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Basic Data Types<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">int<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Used to store whole numbers.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>int number = 10;<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">float<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Used to store decimal values.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>float price = 99.5;<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">double<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Used to store large decimal numbers with more precision.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>double value = 123.456789;<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">char<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Used to store a single character.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>char grade = 'A';<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">bool<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Used to store true or false values.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>bool isPassed = true;<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">string<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Used to store text.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>string name = \"Ali\";<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Example Program<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;iostream&gt;<br>using namespace std;<br><br>int main() {<br>    int age = 18;<br>    float marks = 85.5;<br>    char grade = 'A';<br>    bool passed = true;<br><br>    cout &lt;&lt; age &lt;&lt; endl;<br>    cout &lt;&lt; marks &lt;&lt; endl;<br>    cout &lt;&lt; grade &lt;&lt; endl;<br>    cout &lt;&lt; passed &lt;&lt; endl;<br><br>    return 0;<br>}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Output<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>18<br>85.5<br>A<br>1<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Derived Data Types<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Derived data types are created from basic data types.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Examples:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Arrays<\/li>\n\n\n\n<li>Pointers<\/li>\n\n\n\n<li>Functions<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>int numbers&#91;5];<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">User-Defined Data Types<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">These are created by the programmer.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Examples:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Structures<\/li>\n\n\n\n<li>Classes<\/li>\n\n\n\n<li>Enumerations<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Example:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>struct Student {<br>    string name;<br>    int age;<br>};<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Size of Common Data Types<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Data Type<\/th><th>Typical Size<\/th><\/tr><\/thead><tbody><tr><td>int<\/td><td>4 bytes<\/td><\/tr><tr><td>float<\/td><td>4 bytes<\/td><\/tr><tr><td>double<\/td><td>8 bytes<\/td><\/tr><tr><td>char<\/td><td>1 byte<\/td><\/tr><tr><td>bool<\/td><td>1 byte<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Why Data Types are Important<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Data types are important because they:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Define memory usage<\/li>\n\n\n\n<li>Improve program efficiency<\/li>\n\n\n\n<li>Prevent invalid operations<\/li>\n\n\n\n<li>Help organize data correctly<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Real-Life Example<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>int \u2192 Number of students<\/li>\n\n\n\n<li>float \u2192 Product price<\/li>\n\n\n\n<li>char \u2192 Grade letter<\/li>\n\n\n\n<li>bool \u2192 Pass or fail status<\/li>\n\n\n\n<li>string \u2192 Person name<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Data types are a fundamental part of C++ programming. They define what kind of data can be stored and processed in a program. Understanding data types helps write efficient, accurate, and organized code.<audio autoplay=\"\"><\/audio><\/p>\n\n\n<div class=\"yoast-breadcrumbs\"><span><span><a href=\"https:\/\/gigz.pk\/cpp\">Home<\/a><\/span> \u00bb <span class=\"breadcrumb_last\" aria-current=\"page\">C++ Fundamentals (Beginner Level) > Basics of Programming > Data Types<\/span><\/span><\/div>\n\n\n<div class=\"schema-faq wp-block-yoast-faq-block\"><\/div>\n","protected":false},"menu_order":8,"template":"","class_list":["post-63","lesson","type-lesson","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.7 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Data Types - Learn C++Language with GiGz.PK<\/title>\n<meta name=\"description\" content=\"Learn C++ data types including int, float, double, char, bool, string, arrays, and user-defined data types.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/gigz.pk\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Data Types - Learn C++Language with GiGz.PK\" \/>\n<meta property=\"og:description\" content=\"Learn C++ data types including int, float, double, char, bool, string, arrays, and user-defined data types.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/gigz.pk\/\" \/>\n<meta property=\"og:site_name\" content=\"Learn C++Language with GiGz.PK\" \/>\n<meta property=\"article:modified_time\" content=\"2026-05-22T06:21:16+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":[\"WebPage\",\"FAQPage\"],\"@id\":\"https:\\\/\\\/gigz.pk\\\/cpp\\\/?lesson=data-types\",\"url\":\"https:\\\/\\\/gigz.pk\\\/\",\"name\":\"Data Types - Learn C++Language with GiGz.PK\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/gigz.pk\\\/cpp\\\/#website\"},\"datePublished\":\"2026-05-19T14:50:18+00:00\",\"dateModified\":\"2026-05-22T06:21:16+00:00\",\"description\":\"Learn C++ data types including int, float, double, char, bool, string, arrays, and user-defined data types.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/gigz.pk\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/gigz.pk\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/gigz.pk\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/gigz.pk\\\/cpp\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"C++ Fundamentals (Beginner Level) > Basics of Programming > Data Types\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/gigz.pk\\\/cpp\\\/#website\",\"url\":\"https:\\\/\\\/gigz.pk\\\/cpp\\\/\",\"name\":\"Learn C++Language with GiGz.PK\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/gigz.pk\\\/cpp\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Data Types - Learn C++Language with GiGz.PK","description":"Learn C++ data types including int, float, double, char, bool, string, arrays, and user-defined data types.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/gigz.pk\/","og_locale":"en_US","og_type":"article","og_title":"Data Types - Learn C++Language with GiGz.PK","og_description":"Learn C++ data types including int, float, double, char, bool, string, arrays, and user-defined data types.","og_url":"https:\/\/gigz.pk\/","og_site_name":"Learn C++Language with GiGz.PK","article_modified_time":"2026-05-22T06:21:16+00:00","twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":["WebPage","FAQPage"],"@id":"https:\/\/gigz.pk\/cpp\/?lesson=data-types","url":"https:\/\/gigz.pk\/","name":"Data Types - Learn C++Language with GiGz.PK","isPartOf":{"@id":"https:\/\/gigz.pk\/cpp\/#website"},"datePublished":"2026-05-19T14:50:18+00:00","dateModified":"2026-05-22T06:21:16+00:00","description":"Learn C++ data types including int, float, double, char, bool, string, arrays, and user-defined data types.","breadcrumb":{"@id":"https:\/\/gigz.pk\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/gigz.pk\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/gigz.pk\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/gigz.pk\/cpp"},{"@type":"ListItem","position":2,"name":"C++ Fundamentals (Beginner Level) > Basics of Programming > Data Types"}]},{"@type":"WebSite","@id":"https:\/\/gigz.pk\/cpp\/#website","url":"https:\/\/gigz.pk\/cpp\/","name":"Learn C++Language with GiGz.PK","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/gigz.pk\/cpp\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/gigz.pk\/cpp\/index.php?rest_route=\/wp\/v2\/lesson\/63","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gigz.pk\/cpp\/index.php?rest_route=\/wp\/v2\/lesson"}],"about":[{"href":"https:\/\/gigz.pk\/cpp\/index.php?rest_route=\/wp\/v2\/types\/lesson"}],"wp:attachment":[{"href":"https:\/\/gigz.pk\/cpp\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=63"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}