<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Basics :: CS3 course</title><link>https://robark.gitlab.io/basics/index.html</link><description>Basics Compile, Link, Execute</description><generator>Hugo</generator><language>en-us</language><lastBuildDate>Tue, 11 May 2021 17:35:38 +0000</lastBuildDate><atom:link href="https://robark.gitlab.io/basics/index.xml" rel="self" type="application/rss+xml"/><item><title>Helloworld</title><link>https://robark.gitlab.io/basics/helloworld/index.html</link><pubDate>Tue, 27 Apr 2021 23:14:40 +0000</pubDate><guid>https://robark.gitlab.io/basics/helloworld/index.html</guid><description>Lesson 1: Hello World Explaining the differences between Python and C/C++.</description></item><item><title>Various</title><link>https://robark.gitlab.io/basics/various/index.html</link><pubDate>Wed, 28 Apr 2021 22:50:31 +0000</pubDate><guid>https://robark.gitlab.io/basics/various/index.html</guid><description>cout, datatypes, escape character, cin, promotion, type casting #include &lt;iostream&gt; // for cout using namespace std; //standard namespace // single line comment /* multi line comments */ int main(){ //https://en.cppreference.com/w/c/types/limits cout&lt;&lt;"hello"&lt;&lt;endl; int i(-1); i=2147483647; //biggest int i=-2147483648; //smallest int cout&lt;&lt;i&lt;&lt;endl; unsigned int ui(1); ui=4294967295; //biggest unsigned int ui = 0; //smallest unsigned int cout&lt;&lt;ui&lt;&lt;endl; long int l(999999999); short s(9); float f(-15.5); double d(9.11e-33); long double ld(4.4); char c('A'); char c2(65); unsigned char uc(255); bool b(false); //0 bool b2(true); //1 or bool b3(88); //anything other than 0 is true cout &lt;&lt; "int "&lt;&lt;sizeof(i)&lt;&lt;endl; cout &lt;&lt; "long "&lt;&lt;sizeof(l)&lt;&lt;endl; cout &lt;&lt; "unsigned int "&lt;&lt;sizeof(ui)&lt;&lt;endl; cout &lt;&lt; "short "&lt;&lt;sizeof(s)&lt;&lt;endl; cout &lt;&lt; "float "&lt;&lt;sizeof(f)&lt;&lt;endl; cout &lt;&lt; "double "&lt;&lt;sizeof(d)&lt;&lt;endl; cout &lt;&lt; "long double "&lt;&lt;sizeof(ld)&lt;&lt;endl; cout &lt;&lt; "char "&lt;&lt;sizeof(c)&lt;&lt;endl; cout &lt;&lt; "char c2 = "&lt;&lt; short(c2) &lt;&lt;" with a size of "&lt;&lt;sizeof(c2)&lt;&lt;endl; cout &lt;&lt; char(67)&lt;&lt;endl; cout &lt;&lt; "unsigned char"&lt;&lt;short(uc)&lt;&lt;" "&lt;&lt;sizeof(uc)&lt;&lt;endl; //casting cout &lt;&lt; "bool size "&lt;&lt;sizeof(b)&lt;&lt;endl; cout &lt;&lt; "bool b2 "&lt;&lt;b2&lt;&lt;" b "&lt;&lt;b&lt;&lt;endl; return 0; }</description></item><item><title>If ladders</title><link>https://robark.gitlab.io/basics/iflad/index.html</link><pubDate>Thu, 06 May 2021 22:00:24 +0000</pubDate><guid>https://robark.gitlab.io/basics/iflad/index.html</guid><description>If ladders, arrays, data conversion if ladder, auto, bool #include &lt;iostream&gt; using namespace std; int main(){ int x; x=1; int y=2; int z(3); auto a=81; //infers that a is an int auto b=3.14; //b double auto c("Hello"); //c string auto d='A'; // d char //bool e(true); //bool f(false); cout&lt;&lt; x&lt;&lt;y&lt;&lt;z&lt;&lt;a&lt;&lt;b&lt;&lt;c&lt;&lt;d; if (a&lt;9) { cout&lt;&lt;"en"; cout&lt;&lt;"o"; } else if (d=='A') { cout&lt;&lt;"d is A"; } else { cout&lt;&lt;"a is not less than 9"; } return 0; } C arrays and strings #include &lt;cstring&gt; #include &lt;iostream&gt; using namespace std; int main(){ char x[4]; /* x[0]='a'; x[1]='b'; x[2]='c'; x[3]='\0'; //null char null terminated c-string */ strncpy(x, "abcaaaaaaaaaaaaaaaaaaaa", sizeof(x)-1); //string s("abc"); //cout&lt;&lt;s; cout&lt;&lt;x&lt;&lt;endl; //C style printf("the string %s has %i chars \n", x, strlen(x)); return 0; } Data conversion //example convert string -&gt; int string age("14"); //string age="14"; cout&lt;&lt; atoi(age.c_str())+1 &lt;&lt; endl; //age.c_str() convert c++ to c string // or if using C++11 cout &lt;&lt; stoi(age) &lt;&lt; endl; //example convert int -&gt; string int num(14); stringstream ss; ss &lt;&lt; num; cout &lt;&lt; ss.str() &lt;&lt; endl; //or if using C++11 cout &lt;&lt; to_string(num)+"hi" &lt;&lt; endl; //example of c-string -&gt; double char n[32]; strncpy(n,"12",32); cout&lt;&lt;strtod(n, NULL)+1; //example of c++ string -&gt; double string nn("12.03"); cout&lt;&lt;endl&lt;&lt;strtod(nn.c_str(), NULL)+1;</description></item><item><title>Loops</title><link>https://robark.gitlab.io/basics/loops/index.html</link><pubDate>Mon, 10 May 2021 19:15:16 +0000</pubDate><guid>https://robark.gitlab.io/basics/loops/index.html</guid><description>While and for loops Integer array loops
#include &lt;iostream&gt; using namespace std; int main(){ int a[4] = {11,22,33,44}; //initialization list for (int x =0; x &lt; 4; x++) cout &lt;&lt; a[x] &lt;&lt; endl; for (auto x: a) cout &lt;&lt; x &lt;&lt; endl; return 0; } C string array loops
#include &lt;cstring&gt; //for strlen #include &lt;iostream&gt; using namespace std; int main(){ char s[12]="Hello World"; cout &lt;&lt; s &lt;&lt; endl; for (int x =0; x &lt; strlen(s); x++) cout &lt;&lt; s[x]; cout &lt;&lt; endl; for (auto x: s) cout &lt;&lt; x ; cout &lt;&lt; endl; return 0; }</description></item><item><title>Functions</title><link>https://robark.gitlab.io/basics/functions/index.html</link><pubDate>Tue, 11 May 2021 17:35:38 +0000</pubDate><guid>https://robark.gitlab.io/basics/functions/index.html</guid><description>Functions: pass by value, pass by reference, default arguments, global variables, static variables Global variables
#include &lt;iostream&gt; using namespace std; int g=0; //global var declared outside any function void foo(){ int g=1; cout&lt;&lt;"global g "&lt;&lt;::g&lt;&lt;endl; // 0 :: scope resolution operator cout&lt;&lt;"local g "&lt;&lt;g&lt;&lt;endl; // 1 } void boo(){ cout&lt;&lt;g&lt;&lt;endl; // 0 global } int main(){ foo(); boo(); cout&lt;&lt;"in main "&lt;&lt;g&lt;&lt;endl; // 0 global return 0; } Static Variables</description></item></channel></rss>