1"use strict";(self.webpackChunkc_cpp=self.webpackChunkc_cpp||[]).push([["8427"],{8165(e,n,t){t.r(n),t.d(n,{metadata:()=>r,default:()=>h,frontMatter:()=>c,contentTitle:()=>u,toc:()=>p,assets:()=>d});var r=JSON.parse('{"id":"basics/data-types","title":"Basic data types","description":"C/C++ statically typed languages. Before we can store certain values in the","source":"@site/docs/basics/data-types.mdx","sourceDirName":"basics","slug":"/basics/data-types","permalink":"/basics/data-types","draft":false,"unlisted":false,"editUrl":"https://github.com/pranabdas/c-cpp/blob/main/docs/basics/data-types.mdx","tags":[],"version":"current","frontMatter":{"title":"Basic data types"},"sidebar":"docs","previous":{"title":"Add two integers","permalink":"/basics/add-two-integers"},"next":{"title":"Control flow","permalink":"/basics/control-flow"}}'),a=t(4848),i=t(8453),s=t(773),o=t(7250),l=t(1113);let c={title:"Basic data types"},u,d={},p=[];function f(e){let n={admonition:"admonition",code:"code",p:"p",strong:"strong",...(0,i.R)(),...e.components};return(0,a.jsxs)(a.Fragment,{children:[(0,a.jsx)(n.p,{children:"C/C++ statically typed languages. Before we can store certain values in the\ncomputer memory, we need to declare their data types."}),"\n","\n",(0,a.jsxs)(s.A,{groupId:"language",children:[(0,a.jsx)(o.A,{value:"C",children:(0,a.jsx)(l.A,{language:"c",title:"src/c/basics/02-data-types.c",showLineNumbers:!0,children:'#include <stdio.h>\n\nint main()\n{\n unsigned int u_num = 8;\n printf("Unsigned integer: %u\\n", u_num);\n\n int num = -9;\n printf("Integer: %d\\n", num);\n\n long int large_num = 3988764563425;\n printf("Large integer: %ld\\n", large_num);\n\n float num_f = 3.14159;\n printf("Float: %f\\n", num_f);\n\n double num_d = 3.141592653589793;\n printf("Double precision float: %16.15f\\n", num_d);\n\n char c = \'a\'; // char data type must be wrapped in single quotes\n // double quote in c/c++ denotes string literal which is an\n // array of char with null terminator (\\0)\n printf("Char: %c\\n", c);\n printf("ASCII value of char: %d\\n", c);\n printf("char corresponding to ascii value 98: %c\\n", 98);\n\n char message[] = "Hello"; // string literal\n // same as {\'H\', \'e\', \'l\', \'l\', \'o\', \'\\0\'}\n printf("String: %s\\n", message);\n\n return 0;\n}\n'})}),(0,a.jsx)(o.A,{value:"C++",children:(0,a.jsx)(l.A,{language:"cpp",title:"src/cpp/basics/02-data-types.cpp",showLineNumbers:!0,children:'#include <iostream>\n#include <iomanip> // setprecision\nusing namespace std;\n\nint main()\n{\n unsigned int u_num = 8;\n cout << "Unsigned integer: " << u_num << endl;\n\n int num = -9;\n cout << "Integer: " << num << endl;\n\n long int large_num = 3988764563425;\n cout << "Large integer: " << large_num << endl;\n\n float num_f = 3.14159;\n cout << "Float: " << num_f << endl;\n\n double num_d = 3.141592653589793;\n cout << "Double precision float: " << setprecision(16) << num_d << endl;\n\n char c = \'a\';\n cout << "Char: " << c << endl;\n cout << "ASCII value of char: " << int(c) << endl;\n cout << "char corresponding to ascii value 98: " << char(98) << endl;\n\n char message[] = "Hello";\n cout << "String: " << message << endl;\n\n return 0;\n}\n'})})]}),"\n",(0,a.jsx)(n.admonition,{type:"info",children:(0,a.jsxs)(n.p,{children:["A decimal integer cannot start with ",(0,a.jsx)(n.code,{children:"0"}),", in that case it is considered octal\nbase. For example, ",(0,a.jsx)(n.code,{children:"076"})," denotes ",(0,a.jsx)(n.code,{children:"63"})," in decimal notation."]})}),"\n",(0,a.jsxs)(n.admonition,{title:"Good to know",type:"tip",children:[(0,a.jsx)(n.p,{children:"For numeric data types that span multiple bytes, the order of arrangement of\nbytes is important. Depending on the processor architecture, there are two\nformats: big endian and little endian."}),(0,a.jsxs)(n.p,{children:[(0,a.jsx)(n.strong,{children:"Big endian:"})," the most significant bits occupy the lower address. This\nrepresentation is used in powerpc processor."]}),(0,a.jsxs)(n.p,{children:[(0,a.jsx)(n.strong,{children:"Little endian:"})," the least significant bits occupy the lower address. This\nformat is used in all ",(0,a.jsx)(n.strong,{children:"x86"})," compatible processors."]})]})]})}function h(e={}){let{wrapper:n}={...(0,i.R)(),...e.components};return n?(0,a.jsx)(n,{...e,children:(0,a.jsx)(f,{...e})}):f(e)}},7250(e,n,t){t.d(n,{A:()=>o});var r=t(4848);t(6540);var a=t(4164),i=t(7663);function s(e){let{children:n,className:t,hidden:i}=e;return(0,r.jsx)("div",{role:"tabpanel",className:(0,a.A)("tabItem_Ymn6",t),hidden:i,children:n})}function o(e){let{children:n,className:t,value:a}=e,{selectedValue:o,lazy:l}=(0,i.uc)(),c=a===o;return!c&&l?null:(0,r.jsx)(s,{className:t,hidden:!c,children:n})}},773(e,n,t){t.d(n,{A:()=>p});var r=t(4848);t(6540);var a=t(4164),i=t(8287),s=t(7663),o=t(8584),l=t(9863);function c(e){let{className:n}=e,{selectedValue:t,selectValue:i,tabValues:l,block:c}=(0,s.uc)(),u=[],{blockElementScrollPositionUntilNextRender:d}=(0,o.a_)(),p=e=>{let n=e.currentTarget,r=l[u.indexOf(n)].value;r!==t&&(d(n),i(r))},f=e=>{var n,t;let r=null;switch(e.key){case"Enter":p(e);break;case"ArrowRight":{let t=u.indexOf(e.currentTarget)+1;r=null!=(n=u[t])?n:u[0];break}case"ArrowLeft":{let n=u.indexOf(e.currentTarget)-1;r=null!=(t=u[n])?t:u[u.length-1]}}null==r||r.focus()};return(0,r.jsx)("ul",{role:"tablist","aria-orientation":"horizontal",className:(0,a.A)("tabs",{"tabs--block":c},n),children:l.map(e=>{var n,i;let{value:s,label:o,attributes:l}=e;return(0,r.jsx)("li",(n=function(e){for(var n=1;n<arguments.length;n++){var t=null!=arguments[n]?arguments[n]:{},r=Object.keys(t);"function"==typeof Object.getOwnPropertySymbols&&(r=r.concat(Object.getOwnPropertySymbols(t).filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.forEach(function(n){var r;r=t[n],n in e?Object.defineProperty(e,n,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[n]=r})}return e}({role:"tab",tabIndex:t===s?0:-1,"aria-selected":t===s,ref:e=>{u.push(e)},onKeyDown:f,onClick:p},l),i=i={className:(0,a.A)("tabs__item","tabItem_LNqP",null==l?void 0:l.className,{"tabs__item--active":t===s}),children:null!=o?o:s},Object.getOwnPropertyDescriptors?Object.defineProperties(n,Object.getOwnPropertyDescriptors(i)):(function(e){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var t=Object.getOwnPropertySymbols(e);n.push.apply(n,t)}return n}
1)(Object(i)).forEach(function(e){Object.defineProperty(n,e,Object.getOwnPropertyDescriptor(i,e))}),n),s)})})}function u(e){let{children:n}=e;return(0,r.jsx)("div",{className:"margin-top--md",children:n})}function d(e){let{className:n,children:t}=e;return(0,r.jsxs)("div",{className:(0,a.A)(i.G.tabs.container,"tabs-container","tabList__CuJ"),children:[(0,r.jsx)(c,{className:n}),(0,r.jsx)(u,{children:t})]})}function p(e){let n=(0,l.A)(),t=(0,s.OC)(e);return(0,r.jsx)(s.O_,{value:t,children:(0,r.jsx)(d,{className:e.className,children:(0,s.vT)(e.children)})},String(n))}},7663(e,n,t){t.d(n,{OC:()=>p,O_:()=>b,uc:()=>h,vT:()=>u});var r=t(4848),a=t(6540),i=t(6347),s=t(9989),o=t(6629),l=t(618),c=t(1367);function u(e){return a.Children.toArray(e).filter(e=>"\n"!==e)}function d(e){let{value:n,tabValues:t}=e;return t.some(e=>e.value===n)}function p(e){var n,t;let r,{defaultValue:u,queryString:p=!1,groupId:f}=e,h=function(e){let{values:n,children:t}=e;return(0,a.useMemo)(()=>{let e=null!=n?n:a.Children.toArray(t).flatMap(e=>{if(!e)return[];if((0,a.isValidElement)(e)&&function(e){let{props:n}=e;return!!n&&"object"==typeof n&&"value"in n}(e))return[e];let n="string"==typeof e.type?e.type:e.type.name;throw Error("Docusaurus error: Bad <Tabs> child <".concat(n,'>: all children of the <Tabs> component should be <TabItem>, and every <TabItem> should have a unique "value" prop.\nIf you do not want to pass on a "value" prop to the direct children of <Tabs>, you can also pass an explicit <Tabs values={...}> prop.'))}).map(e=>{let{props:{value:n,label:t,attributes:r,default:a}}=e;return{value:n,label:t,attributes:r,default:a}}),r=(0,l.XI)(e,(e,n)=>e.value===n.value);if(r.length>0)throw Error('Docusaurus error: Duplicate values "'.concat(r.map(e=>"'".concat(e.value,"'")).join(", "),'" found in <Tabs>. Every value needs to be unique.'));return e},[n,t])}(e),[b,m]=(0,a.useState)(()=>(function(e){var n;let{defaultValue:t,tabValues:r}=e;if(0===r.length)throw Error("Docusaurus error: the <Tabs> component requires at least one <TabItem> children component");if(t){if(!d({value:t,tabValues:r}))throw Error('Docusaurus error: The <Tabs> has a defaultValue "'.concat(t,'" but none of its children has the corresponding value. Available values are: ').concat(r.map(e=>e.value).join(", "),". If you intend to show no default tab, use defaultValue={null} instead."));return t}let a=null!=(n=r.find(e=>e.default))?n:r[0];if(!a)throw Error("Unexpected error: 0 tabValues");return a.value})({defaultValue:u,tabValues:h})),[g,y]=function(e){let{queryString:n=!1,groupId:t}=e,r=(0,i.W6)(),s=function(e){let{queryString:n=!1,groupId:t}=e;if("string"==typeof n)return n;if(!1===n)return null;if(!0===n&&!t)throw Error('Docusaurus error: The <Tabs> component groupId prop is required if queryString=true, because this value is used as the search param name. You can also provide an explicit value such as queryString="my-search-param".');return null!=t?t:null}({queryString:n,groupId:t});return[(0,o.aZ)(s),(0,a.useCallback)(e=>{var n,t;if(!s)return;let a=new URLSearchParams(r.location.search);a.set(s,e),r.replace((n=function(e){for(var n=1;n<arguments.length;n++){var t=null!=arguments[n]?arguments[n]:{},r=Object.keys(t);"function"==typeof Object.getOwnPropertySymbols&&(r=r.concat(Object.getOwnPropertySymbols(t).filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.forEach(function(n){var r;r=t[n],n in e?Object.defineProperty(e,n,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[n]=r})}return e}({},r.location),t=t={search:a.toString()},Object.getOwnPropertyDescriptors?Object.defineProperties(n,Object.getOwnPropertyDescriptors(t)):(function(e){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var t=Object.getOwnPropertySymbols(e);n.push.apply(n,t)}return n})(Object(t)).forEach(function(e){Object.defineProperty(n,e,Object.getOwnPropertyDescriptor(t,e))}),n))},[s,r])]}({queryString:p,groupId:f}),[v,j]=function(e){let{groupId:n}=e,t=n?"docusaurus.tab.".concat(n):null,[r,i]=(0,c.Dv)(t);return[r,(0,a.useCallback)(e=>{t&&i.set(e)},[t,i])]}({groupId:f}),w=d({value:r=null!=g?g:v,tabValues:h})?r:null;return(0,s.A)(()=>{w&&m(w)},[w]),{selectedValue:b,selectValue:(0,a.useCallback)(e=>{if(!d({value:e,tabValues:h}))throw Error("Can't select invalid tab value=".concat(e));m(e),y(e),j(e)},[y,j,h]),tabValues:h,lazy:null!=(n=e.lazy)&&n,block:null!=(t=e.block)&&t}}let f=(0,a.createContext)(null);function h(){let e=a.useContext(f);if(!e)throw Error("useTabsContext() must be used within a Tabs component");return e}function b(e){return(0,r.jsx)(f.Provider,{value:e.value,children:e.children})}}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.