<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://btechwiki.duckdns.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=76.80.63.158</id>
	<title>Bitnami MediaWiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://btechwiki.duckdns.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=76.80.63.158"/>
	<link rel="alternate" type="text/html" href="https://btechwiki.duckdns.org/wiki/Special:Contributions/76.80.63.158"/>
	<updated>2026-12-03T11:58:37Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.35.0</generator>
	<entry>
		<id>https://btechwiki.duckdns.org/index.php?title=Bayes%27_Theorem&amp;diff=984</id>
		<title>Bayes' Theorem</title>
		<link rel="alternate" type="text/html" href="https://btechwiki.duckdns.org/index.php?title=Bayes%27_Theorem&amp;diff=984"/>
		<updated>2023-02-28T23:11:32Z</updated>

		<summary type="html">&lt;p&gt;76.80.63.158: /* Resources */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In case you forgot:&lt;br /&gt;
::&amp;lt;math&amp;gt;P(A|B) = \dfrac{P(B|A)\,P(A)}{P(B)}&amp;lt;/math&amp;gt;&lt;br /&gt;
where, &lt;br /&gt;
* &amp;lt;math&amp;gt;P(A|B)&amp;lt;/math&amp;gt; is the conditional probability that A is true given B&lt;br /&gt;
* &amp;lt;math&amp;gt;P(A), P(B)&amp;lt;/math&amp;gt; are the marginal probabilities that A or B is true&lt;br /&gt;
It's true by the definition of '''conditional probability''':&lt;br /&gt;
::&amp;lt;math&amp;gt;P(A|B) = \dfrac{P(A\cap B)}{P(B)}&amp;lt;/math&amp;gt; where &amp;lt;math&amp;gt;P(A\cap B)&amp;lt;/math&amp;gt; is the '''joint probability''' that both A and B are true&lt;br /&gt;
::&amp;lt;math&amp;gt;P(A\cap B) = P(A|B)\,P(B) = P(B|A)\,P(A)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In other terminology (VanderPlas):&lt;br /&gt;
* &amp;lt;math&amp;gt;P(A|B)&amp;lt;/math&amp;gt; is the '''posterior''', the probability of the model parameters given the data&lt;br /&gt;
* &amp;lt;math&amp;gt; P(B|A)&amp;lt;/math&amp;gt; is the '''likelihood''' &lt;br /&gt;
* &amp;lt;math&amp;gt; P(A) &amp;lt;/math&amp;gt; is the '''model prior''', which encodes knowledge about the model ''before'' considering the data &amp;lt;math&amp;gt;B&amp;lt;/math&amp;gt;&lt;br /&gt;
* &amp;lt;math&amp;gt; P(B) &amp;lt;/math&amp;gt; is the '''model evidence''' (which in practice is a normalization term).&lt;br /&gt;
&lt;br /&gt;
===Resources===&lt;br /&gt;
* The [https://towardsdatascience.com/bayesian-inference-and-markov-chain-monte-carlo-sampling-in-python-bada1beabca7 coin factory] problem&lt;br /&gt;
* Jake VanderPlas's [http://jakevdp.github.io/blog/2014/03/11/frequentism-and-bayesianism-a-practical-intro/ 5 part series] on github&lt;br /&gt;
* [https://nbviewer.org/github/CamDavidsonPilon/Probabilistic-Programming-and-Bayesian-Methods-for-Hackers/blob/master/Chapter1_Introduction/Ch1_Introduction_PyMC2.ipynb Bayesian Methods for Hackers] ported to PyMC3 and Python 3&lt;br /&gt;
* ArviZ documentation on working with [https://python.arviz.org/en/0.14.0/getting_started/WorkingWithInferenceData.html inference data]&lt;br /&gt;
* [https://github.com/pymc-devs/pymc-resources/tree/main/BDA3 Bayesian Data Analysis with Python and PyMC] by Gelman et al. (Code ported to Python)&lt;br /&gt;
* [https://bayesiancomputationbook.com/markdown/chp_01.htmlBayesian Modeling and Computation in Python] by Martin, Kumar &amp;amp; Lao  (ported to Python]&lt;br /&gt;
* [https://github.com/JWarmenhoven/DBDA-python Doing Bayesian Data Analysis] by John Kruschke, ported to Python&lt;br /&gt;
* [https://github.com/pymc-devs/pymc-resources/tree/main/BDA3 Bayesian Data Analysis, 3ed] by Gelman et al, ported to Python&lt;br /&gt;
* [https://ethanweed.github.io/pythonbook/landingpage.html Learn Statistics with Python] by Ethan Weed (refitting of &amp;quot;Learn Stats with R&amp;quot;)&lt;br /&gt;
* Jim Frost's [https://statisticsbyjim.com/basics/ Statistics by Jim]&lt;br /&gt;
* NIST [https://www.itl.nist.gov/div898/handbook/eda/eda.htm Exploratory Data Analysis] pages&lt;br /&gt;
&lt;br /&gt;
===Misc===&lt;br /&gt;
* Python virtual environment [https://realpython.com/python-virtual-environments-a-primer/#what-is-a-python-virtual-environment primer]&lt;br /&gt;
* NBShare notebook on [https://www.nbshare.io/notebook/512285365/PyTorch-Tutorial-A-Complete-Use-Case-Example/ PyTorch] (MNIST example)&lt;br /&gt;
* Highlight data points and text in [https://cmdlinetips.com/2019/11/how-to-highlight-data-points-with-colors-and-text-in-python/ Python charts]&lt;br /&gt;
* RevBayes (a package for phylogenetic analysis, with some good MCMC [https://revbayes.github.io/tutorials/ tutorial] pages&lt;br /&gt;
* [https://www.pymc-labs.io/blog-posts/the-quickest-migration-guide-ever-from-pymc3-to-pymc-v40/ Migration] guide for PyMC 3 to 4&lt;br /&gt;
* Conversion of R statistical functions to [https://github.com/tirthajyoti/Stats-Maths-with-Python/blob/master/R_Functions.py Python]&lt;br /&gt;
* [https://towardsdatascience.com/8-commonly-used-pandas-display-options-you-should-know-a832365efa95 Pandas] display options cheatsheet&lt;/div&gt;</summary>
		<author><name>76.80.63.158</name></author>
	</entry>
	<entry>
		<id>https://btechwiki.duckdns.org/index.php?title=Bayes%27_Theorem&amp;diff=983</id>
		<title>Bayes' Theorem</title>
		<link rel="alternate" type="text/html" href="https://btechwiki.duckdns.org/index.php?title=Bayes%27_Theorem&amp;diff=983"/>
		<updated>2023-02-28T23:09:48Z</updated>

		<summary type="html">&lt;p&gt;76.80.63.158: /* Resources */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In case you forgot:&lt;br /&gt;
::&amp;lt;math&amp;gt;P(A|B) = \dfrac{P(B|A)\,P(A)}{P(B)}&amp;lt;/math&amp;gt;&lt;br /&gt;
where, &lt;br /&gt;
* &amp;lt;math&amp;gt;P(A|B)&amp;lt;/math&amp;gt; is the conditional probability that A is true given B&lt;br /&gt;
* &amp;lt;math&amp;gt;P(A), P(B)&amp;lt;/math&amp;gt; are the marginal probabilities that A or B is true&lt;br /&gt;
It's true by the definition of '''conditional probability''':&lt;br /&gt;
::&amp;lt;math&amp;gt;P(A|B) = \dfrac{P(A\cap B)}{P(B)}&amp;lt;/math&amp;gt; where &amp;lt;math&amp;gt;P(A\cap B)&amp;lt;/math&amp;gt; is the '''joint probability''' that both A and B are true&lt;br /&gt;
::&amp;lt;math&amp;gt;P(A\cap B) = P(A|B)\,P(B) = P(B|A)\,P(A)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In other terminology (VanderPlas):&lt;br /&gt;
* &amp;lt;math&amp;gt;P(A|B)&amp;lt;/math&amp;gt; is the '''posterior''', the probability of the model parameters given the data&lt;br /&gt;
* &amp;lt;math&amp;gt; P(B|A)&amp;lt;/math&amp;gt; is the '''likelihood''' &lt;br /&gt;
* &amp;lt;math&amp;gt; P(A) &amp;lt;/math&amp;gt; is the '''model prior''', which encodes knowledge about the model ''before'' considering the data &amp;lt;math&amp;gt;B&amp;lt;/math&amp;gt;&lt;br /&gt;
* &amp;lt;math&amp;gt; P(B) &amp;lt;/math&amp;gt; is the '''model evidence''' (which in practice is a normalization term).&lt;br /&gt;
&lt;br /&gt;
===Resources===&lt;br /&gt;
* The [https://towardsdatascience.com/bayesian-inference-and-markov-chain-monte-carlo-sampling-in-python-bada1beabca7 coin factory] problem&lt;br /&gt;
* Jake VanderPlas's [http://jakevdp.github.io/blog/2014/03/11/frequentism-and-bayesianism-a-practical-intro/ 5 part series] on github&lt;br /&gt;
* [https://nbviewer.org/github/CamDavidsonPilon/Probabilistic-Programming-and-Bayesian-Methods-for-Hackers/blob/master/Chapter1_Introduction/Ch1_Introduction_PyMC2.ipynb Bayesian Methods for Hackers] ported to PyMC3 and Python 3&lt;br /&gt;
* ArviZ documentation on working with [https://python.arviz.org/en/0.14.0/getting_started/WorkingWithInferenceData.html inference data]&lt;br /&gt;
* [https://github.com/pymc-devs/pymc-resources/tree/main/BDA3 Bayesian Data Analysis with Python and PyMC] by Gelman et al. (Code ported to Python)&lt;br /&gt;
* [https://bayesiancomputationbook.com/markdown/chp_01.htmlBayesian Modeling and Computation in Python] by Martin, Kumar &amp;amp; Lao  (ported to Python]&lt;br /&gt;
* [https://github.com/JWarmenhoven/DBDA-python Doing Bayesian Data Analysis] by John Kruschke, ported to Python&lt;br /&gt;
* [https://github.com/pymc-devs/pymc-resources/tree/main/BDA3 Bayesian Data Analysis, 3ed] by Gelman et al, ported to Python&lt;br /&gt;
* [https://ethanweed.github.io/pythonbook/landingpage.html Learn Statistics with Python] by Ethan Weed (refitting of &amp;quot;Learn Stats with R&amp;quot;)&lt;br /&gt;
* Jim Frost's [https://statisticsbyjim.com/basics/ Statistics by Jim]&lt;br /&gt;
&lt;br /&gt;
===Misc===&lt;br /&gt;
* Python virtual environment [https://realpython.com/python-virtual-environments-a-primer/#what-is-a-python-virtual-environment primer]&lt;br /&gt;
* NBShare notebook on [https://www.nbshare.io/notebook/512285365/PyTorch-Tutorial-A-Complete-Use-Case-Example/ PyTorch] (MNIST example)&lt;br /&gt;
* Highlight data points and text in [https://cmdlinetips.com/2019/11/how-to-highlight-data-points-with-colors-and-text-in-python/ Python charts]&lt;br /&gt;
* RevBayes (a package for phylogenetic analysis, with some good MCMC [https://revbayes.github.io/tutorials/ tutorial] pages&lt;br /&gt;
* [https://www.pymc-labs.io/blog-posts/the-quickest-migration-guide-ever-from-pymc3-to-pymc-v40/ Migration] guide for PyMC 3 to 4&lt;br /&gt;
* Conversion of R statistical functions to [https://github.com/tirthajyoti/Stats-Maths-with-Python/blob/master/R_Functions.py Python]&lt;br /&gt;
* [https://towardsdatascience.com/8-commonly-used-pandas-display-options-you-should-know-a832365efa95 Pandas] display options cheatsheet&lt;/div&gt;</summary>
		<author><name>76.80.63.158</name></author>
	</entry>
	<entry>
		<id>https://btechwiki.duckdns.org/index.php?title=Bayes%27_Theorem&amp;diff=971</id>
		<title>Bayes' Theorem</title>
		<link rel="alternate" type="text/html" href="https://btechwiki.duckdns.org/index.php?title=Bayes%27_Theorem&amp;diff=971"/>
		<updated>2022-12-29T21:02:48Z</updated>

		<summary type="html">&lt;p&gt;76.80.63.158: /* Resources */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;In case you forgot:&lt;br /&gt;
::&amp;lt;math&amp;gt;P(A|B) = \dfrac{P(B|A)\,P(A)}{P(B)}&amp;lt;/math&amp;gt;&lt;br /&gt;
where, &lt;br /&gt;
* &amp;lt;math&amp;gt;P(A|B)&amp;lt;/math&amp;gt; is the conditional probability that A is true given B&lt;br /&gt;
* &amp;lt;math&amp;gt;P(A), P(B)&amp;lt;/math&amp;gt; are the marginal probabilities that A or B is true&lt;br /&gt;
It's true by the definition of '''conditional probability''':&lt;br /&gt;
::&amp;lt;math&amp;gt;P(A|B) = \dfrac{P(A\cap B)}{P(B)}&amp;lt;/math&amp;gt; where &amp;lt;math&amp;gt;P(A\cap B)&amp;lt;/math&amp;gt; is the '''joint probability''' that both A and B are true&lt;br /&gt;
::&amp;lt;math&amp;gt;P(A\cap B) = P(A|B)\,P(B) = P(B|A)\,P(A)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In other terminology (VanderPlas):&lt;br /&gt;
* &amp;lt;math&amp;gt;P(A|B)&amp;lt;/math&amp;gt; is the '''posterior''', the probability of the model parameters given the data&lt;br /&gt;
* &amp;lt;math&amp;gt; P(B|A)&amp;lt;/math&amp;gt; is the '''likelihood''' &lt;br /&gt;
* &amp;lt;math&amp;gt; P(A) &amp;lt;/math&amp;gt; is the '''model prior''', which encodes knowledge about the model ''before'' considering the data &amp;lt;math&amp;gt;B&amp;lt;/math&amp;gt;&lt;br /&gt;
* &amp;lt;math&amp;gt; P(B) &amp;lt;/math&amp;gt; is the '''model evidence''' (which in practice is a normalization term).&lt;br /&gt;
&lt;br /&gt;
===Resources===&lt;br /&gt;
* The [https://towardsdatascience.com/bayesian-inference-and-markov-chain-monte-carlo-sampling-in-python-bada1beabca7 coin factory] problem&lt;br /&gt;
* Jake VanderPlas's [http://jakevdp.github.io/blog/2014/03/11/frequentism-and-bayesianism-a-practical-intro/ 5 part series] on github&lt;br /&gt;
* [https://nbviewer.org/github/CamDavidsonPilon/Probabilistic-Programming-and-Bayesian-Methods-for-Hackers/blob/master/Chapter1_Introduction/Ch1_Introduction_PyMC2.ipynb Bayesian Methods for Hackers] ported to PyMC3 and Python 3&lt;br /&gt;
* ArviZ documentation on working with [https://python.arviz.org/en/0.14.0/getting_started/WorkingWithInferenceData.html inference data]&lt;br /&gt;
* [https://github.com/pymc-devs/pymc-resources/tree/main/BDA3 Bayesian Data Analysis with Python and PyMC] by Gelman et al. (Code ported to Python)&lt;br /&gt;
* [https://bayesiancomputationbook.com/markdown/chp_01.htmlBayesian Modeling and Computation in Python] by Martin, Kumar &amp;amp; Lao  (ported to Python]&lt;br /&gt;
* [https://github.com/JWarmenhoven/DBDA-python Doing Bayesian Data Analysis] by John Kruschke, ported to Python&lt;br /&gt;
&lt;br /&gt;
===Misc===&lt;br /&gt;
* Python virtual environment [https://realpython.com/python-virtual-environments-a-primer/#what-is-a-python-virtual-environment primer]&lt;br /&gt;
* NBShare notebook on [https://www.nbshare.io/notebook/512285365/PyTorch-Tutorial-A-Complete-Use-Case-Example/ PyTorch] (MNIST example)&lt;br /&gt;
* Highlight data points and text in [https://cmdlinetips.com/2019/11/how-to-highlight-data-points-with-colors-and-text-in-python/ Python charts]&lt;br /&gt;
* RevBayes (a package for phylogenetic analysis, with some good MCMC [https://revbayes.github.io/tutorials/ tutorial] pages&lt;/div&gt;</summary>
		<author><name>76.80.63.158</name></author>
	</entry>
	<entry>
		<id>https://btechwiki.duckdns.org/index.php?title=C_language&amp;diff=852</id>
		<title>C language</title>
		<link rel="alternate" type="text/html" href="https://btechwiki.duckdns.org/index.php?title=C_language&amp;diff=852"/>
		<updated>2022-03-24T22:06:09Z</updated>

		<summary type="html">&lt;p&gt;76.80.63.158: /* Structures */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Elements of C==&lt;br /&gt;
Sources&lt;br /&gt;
* [http://robertseacord.com/wp/errata/ Effective C ]by Robert Seacord&lt;br /&gt;
* [https://www.oreilly.com/library/view/21st-century-c/9781449344382/ 21st Century C] by Ben Clemens&lt;br /&gt;
* [https://shop.learncodethehardway.org/products/contents/3/ Learn C the Hard Way] by Zed Shaw&lt;br /&gt;
* [https://link.springer.com/book/10.1007/978-1-4842-6128-6 Practical Numerical C Programming] and [https://learning.oreilly.com/library/view/numerical-c-applied/9781484250648/ Numerical C] by Philip Joyce&lt;br /&gt;
* [https://link.springer.com/book/10.1007/978-1-4842-6927-5 Pointers in C Programming] by Thomas Mailund&lt;br /&gt;
* [https://www.packtpub.com/product/learn-c-programming-second-edition/9781801078450 Learn C Programming] by Jeff Szuhay&lt;br /&gt;
* [https://www.packtpub.com/product/practical-c-programming/9781838641108 Practical C Programming] by B.M. Harwani&lt;br /&gt;
* [https://github.com/Apress/practical-c Practical C] by Giulio Zambon (2016) &lt;br /&gt;
&lt;br /&gt;
===Basics===&lt;br /&gt;
From ''Effective C'' by Robert Seacord&lt;br /&gt;
;Objects, Functions, Types and Pointers&lt;br /&gt;
* '''object''': storage used to represent values. (Per ISO/IEC 9989:2018: &amp;quot;a region of data storage in the execution environment, the contents of which can represent values.  A '''variable''' is an example of an object. An object with '''type''' &amp;lt;code&amp;gt;int&amp;lt;/code&amp;gt; contains and integer value. E.g. why types are important: the ''text'' number 1 in IEEE 754 (ASCII, roughly) is specified by 0x3f80000, which a little over a billion as a decimal. &lt;br /&gt;
* '''functions''': are not objects, but do have types. A function is defined by both its return type and the number and types of its parameters. &lt;br /&gt;
* '''types''': &amp;lt;code&amp;gt;int, char, bool, float, long int...&amp;lt;/code&amp;gt;&lt;br /&gt;
* '''pointers''': an address or location in memory where an object or function is stored. Pointer types derive from the ''referenced'' function. or object type. E.g., &amp;lt;code&amp;gt;*char&amp;lt;/code&amp;gt; is called a ''pointer to char''. &lt;br /&gt;
* Because objects and functions are different things, object pointers differ from function pointers&lt;br /&gt;
* In the swap program below the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; function declares two variables of type &amp;lt;code&amp;gt;int&amp;lt;/code&amp;gt;, using the combination of a type (int), an identifier (a,b) and a value (21,17). Assigning the values is also called ''initialization&lt;br /&gt;
&lt;br /&gt;
* '''parameters''': objects declared as part of a function declaration that acquire value on entry to the function&lt;br /&gt;
* '''argruments''': comma-separated expressions included in the function call expression (whether values or pointers)&lt;br /&gt;
* '''pass-by-value''': C's default behavior. When you provide an argument to a function, its value is copied into a distinct variable for use within that function. When the values of the parameters are changed, the values in the caller are unaffected because they are distinct objects.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=C&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
void swap(int *pa, int *pb) {&lt;br /&gt;
  int t = *pa;&lt;br /&gt;
  *pa = *pb;&lt;br /&gt;
  *pb = t;&lt;br /&gt;
  //  int t = a;&lt;br /&gt;
  //a = b;&lt;br /&gt;
  //b = t;&lt;br /&gt;
  printf(&amp;quot;swap: a = %d, b = %d\n&amp;quot;, *pa,*pb);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int main(void){&lt;br /&gt;
  int a = 21;&lt;br /&gt;
  int b = 17; &lt;br /&gt;
  swap(&amp;amp;a, &amp;amp;b);&lt;br /&gt;
  printf(&amp;quot;main: a = %d, b = %d\n&amp;quot;, a, b);&lt;br /&gt;
  &lt;br /&gt;
  return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
&lt;br /&gt;
* The commented lines in the &amp;lt;code&amp;gt;swap&amp;lt;/code&amp;gt; function show the original program, which failed to swap &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;'s values, because they were being passed by value rather than reference. The corrected version (above) declares and dereferences pointers with the '''indirection''' operator (*)&lt;br /&gt;
* In the new version, the line &amp;lt;code&amp;gt;*pa=*pb&amp;lt;/code&amp;gt; serves to: &lt;br /&gt;
# deference the pointer &amp;lt;code&amp;gt;pb&amp;lt;/code&amp;gt;&lt;br /&gt;
# reads the referenced value&lt;br /&gt;
# dereference the pointer &amp;lt;code&amp;gt;pa&amp;lt;/code&amp;gt; &lt;br /&gt;
# overwrite the value at the location referenced by &amp;lt;code&amp;gt;pa&amp;lt;/code&amp;gt; with the value referenced by &amp;lt;code&amp;gt;pb&amp;lt;/code&amp;gt; &lt;br /&gt;
* in the main function, &amp;lt;code&amp;gt;&amp;amp;a&amp;lt;/code&amp;gt; , the unary &amp;amp; operator (''address-of'' operator) generates a pointer to its operand. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=C&amp;gt;&lt;br /&gt;
void increment(void) {&lt;br /&gt;
  static unsigned int counter = 0;&lt;br /&gt;
  counter++; &lt;br /&gt;
  printf(&amp;quot;%d&amp;quot;, counter);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int main(void) {&lt;br /&gt;
  for (int i = 0; i &amp;lt; 5; i++) {&lt;br /&gt;
    increment();&lt;br /&gt;
  }&lt;br /&gt;
  return 0; &lt;br /&gt;
} &lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* '''Scope/Lifetime''': scope applies to identifiers, lifetime applies to objects&lt;br /&gt;
* '''Storage duration''': automatic, static, thread, allocated&lt;br /&gt;
* '''Alignment''': object types have restrictions on the addresses at which they may be stored. an ''alignment'' is the number of bytes between successive addresses at which a given object can be allocated. Traditionally done with linker commands or overallocating memory with &amp;lt;code&amp;gt;malloc&amp;lt;/code&amp;gt;, followed by rounding the address up to nearest power of 2. &lt;br /&gt;
* C11 sorted most of this out. Alignments are values of type &amp;lt;code&amp;gt;size_t&amp;lt;/code&amp;gt;. Valid assignments are non-negative powers of 2. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=C&amp;gt;&lt;br /&gt;
struct S {&lt;br /&gt;
  int i; double d; char c;&lt;br /&gt;
};&lt;br /&gt;
int main(void) {&lt;br /&gt;
  unsigned char bad_buff[sizeof(struct S)];&lt;br /&gt;
  _Alignas(struct S) unsigned char good_buff[sizeof(struct S)];&lt;br /&gt;
  struct S *bad_s_ptr = (struct S *)bad_buff;   // wrong pointer alignment&lt;br /&gt;
  struct S *good_s_ptr = (struct S *)good_buff; // correct pointer alignment&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above code &lt;br /&gt;
&lt;br /&gt;
;Object Types&lt;br /&gt;
* Boolean: declare as &amp;lt;code&amp;gt;bool&amp;lt;/code&amp;gt;; contains either 0 or 1. (Also denoted &amp;lt;code&amp;gt;_Bool&amp;lt;/code&amp;gt;&lt;br /&gt;
* Character: &amp;lt;code&amp;gt; char, signed char, unsigned char&amp;lt;/code&amp;gt;&lt;br /&gt;
* Numeric: &amp;lt;code&amp;gt;signed char, short int, int, long, long long int&amp;lt;/code&amp;gt;. For each there is a corresponding unsigned type that uses the same amount of storage (but obviously only 1/2 the range on the positive side). &lt;br /&gt;
* Enumerations: allows type definition by assigning names (&amp;quot;enumerators&amp;quot;) to integer values. E.g., {S,M,T,W,Th,F,Sa}&lt;br /&gt;
* Floating-point: &amp;lt;code&amp;gt;float, double, long double&amp;lt;/code&amp;gt;. &lt;br /&gt;
* void: the keyword &amp;lt;code&amp;gt;void&amp;lt;/code&amp;gt; means &amp;quot;cannot hold any value&amp;quot;. However, &amp;lt;code&amp;gt;void *&amp;lt;/code&amp;gt; means the pointer can reference ''any'' object. &lt;br /&gt;
;Function Types&lt;br /&gt;
* types are all derived. Name and return type are specified by the ''function declarator''. Parameter types must be specified unless of type &amp;lt;code&amp;gt;void&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=C&amp;gt;&lt;br /&gt;
int max(int a, int b)&lt;br /&gt;
{ return a &amp;gt; b ? a : b; }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* Here is a function that returns an &amp;lt;code&amp;gt;int&amp;lt;/code&amp;gt;. The declarator is &amp;lt;code&amp;gt;max(int a, int b)&amp;lt;/code&amp;gt; and the function body is the 2nd line&lt;br /&gt;
* The function specification (line 2) may not include any type qualifiers (e.g., int, char, etc.)&lt;br /&gt;
&lt;br /&gt;
;Derived Types &lt;br /&gt;
pointers, arrays, type definitions, structures and unions&lt;br /&gt;
*'''Pointers''': derived from the function or object it points to, which is the ''referenced'' type. E.g., &amp;lt;code&amp;gt;int i= 17; int *ip = &amp;amp;i;&amp;lt;/code&amp;gt;, &lt;br /&gt;
declares the variable &amp;lt;code&amp;gt;ip&amp;lt;/code&amp;gt; as a pointer to int and assigns it the address of i. '''The unary * operator converts a pointer to a type into a value of that type.''' Consider &amp;lt;code&amp;gt;ip = &amp;amp;*ip;&amp;lt;/code&amp;gt;. Here * is ''dereferencing'' &amp;lt;code&amp;gt;ip&amp;lt;/code&amp;gt;. It takes the address using &amp;amp; and retrieves the pointer. &lt;br /&gt;
* '''Arrays''': contiguously allocated sequence of objects of the same type. E.g. &amp;lt;code&amp;gt;int ia[11], float *afp[17];&amp;lt;/code&amp;gt;. To declare a matrix, use something like &amp;lt;code&amp;gt;int arr[3][5];&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=C&amp;gt;&lt;br /&gt;
void func(int arr[5]);&lt;br /&gt;
int main(void) {&lt;br /&gt;
  unsigned int i = 0;&lt;br /&gt;
  unsigned int j = 0;&lt;br /&gt;
  int arr[3][5];&lt;br /&gt;
  u func(arr[i]);&lt;br /&gt;
  v int x = arr[i][j];&lt;br /&gt;
  return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
What's happening? &lt;br /&gt;
When the function calls &amp;lt;code&amp;gt;arr[i]&amp;lt;/code&amp;gt;, a bunch of shit happens:&lt;br /&gt;
# &amp;lt;code&amp;gt;arr&amp;lt;/code&amp;gt; is converted to a pointer to the initial 5-element int array, starting at &amp;lt;code&amp;gt;arr[i]&amp;lt;/code&amp;gt;&lt;br /&gt;
# &amp;lt;code&amp;gt;i&amp;lt;/code&amp;gt; is scaled to the type of &amp;lt;code&amp;gt;arr&amp;lt;/code&amp;gt; by multiplying it by the size of one array of 5 int objects&lt;br /&gt;
# The results from the above are added&lt;br /&gt;
# Indirection is applied to the result to produce an array of 5 int elements&lt;br /&gt;
&lt;br /&gt;
====Structures====&lt;br /&gt;
* contain sequentially allocated memory objects&lt;br /&gt;
* objects have their own names and may or may not share the same type (unlike arrays, which are monotyyped); similar to records&lt;br /&gt;
* below, the structure contains 3 objects, &amp;lt;code&amp;gt;signum, signame, sigdesc&amp;lt;/code&amp;gt;&lt;br /&gt;
* the last line identifies the whole object as &amp;lt;code&amp;gt;sigline&amp;lt;/code&amp;gt; and having a pointer of &amp;lt;code&amp;gt;*sigline_p&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=C&amp;gt;&lt;br /&gt;
struct sigrecord {&lt;br /&gt;
  int signum;&lt;br /&gt;
  char signame[20];&lt;br /&gt;
  char sigdesc[100];&lt;br /&gt;
} sigline, *sigline_p;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Now that the struct has been created we'd like to reference its members, using the &amp;quot;structure member operator (&amp;lt;math&amp;gt;\cdot&amp;lt;/math&amp;gt;&amp;quot;; like the dot operator in Python and other langs). &lt;br /&gt;
*  a pointer to a struct can reference its members with the (-&amp;gt;) structure pointer operator&lt;br /&gt;
* the first 3 lines directly access members of the &amp;lt;code&amp;gt;sigline&amp;lt;/code&amp;gt; object. The middle line assigns its address to the &amp;lt;code&amp;gt;sigline_p&amp;lt;/code&amp;gt; pointer. &lt;br /&gt;
* the last 3 lines indirectly access members of the struct. &lt;br /&gt;
&amp;lt;syntaxhighlight lang=C&amp;gt;&lt;br /&gt;
sigline.signum = 5;&lt;br /&gt;
strcpy(sigline.signame, &amp;quot;SIGINT&amp;quot;);&lt;br /&gt;
strcpy(sigline.sigdesc, &amp;quot;Interrupt from keyboard&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
sigline_p = &amp;amp;sigline;&lt;br /&gt;
&lt;br /&gt;
sigline_p-&amp;gt;signum = 5;&lt;br /&gt;
strcpy(sigline_p-&amp;gt;signame, &amp;quot;SIGINT&amp;quot;);&lt;br /&gt;
strcpy(sigline_p-&amp;gt;sigdesc, &amp;quot;Interrupt from keyboard&amp;quot;);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; Unions&lt;br /&gt;
* Similar to structs, but memory for member objects overlaps&lt;br /&gt;
* Primarily used to conserve memory and used to contain mixed types (e.g., ints and floats)&lt;br /&gt;
* access elements with dot operator; reference members with the -&amp;gt; operator&lt;br /&gt;
&lt;br /&gt;
; Tags &amp;amp; typedefs&lt;br /&gt;
* naming mechanism for structs, unions and enumerations&lt;br /&gt;
* declare a tag for a struct s: &amp;lt;code&amp;gt;struct s &amp;lt;mytag&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
* use a &amp;lt;code&amp;gt;typedef&amp;lt;/code&amp;gt; to declare an alias for an existing type, without creating a new type&lt;br /&gt;
* here's an example:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=C&amp;gt;&lt;br /&gt;
typedef signed char schar_type, *schar_p, (*fp)(void); &lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* declare schar_type as an alias for signed char. schar_p as an alias for signed char*, and fp as an alias for signed char(*)(void).&lt;br /&gt;
&lt;br /&gt;
===Arithmetic Types===&lt;/div&gt;</summary>
		<author><name>76.80.63.158</name></author>
	</entry>
	<entry>
		<id>https://btechwiki.duckdns.org/index.php?title=C_language&amp;diff=851</id>
		<title>C language</title>
		<link rel="alternate" type="text/html" href="https://btechwiki.duckdns.org/index.php?title=C_language&amp;diff=851"/>
		<updated>2022-03-24T21:53:38Z</updated>

		<summary type="html">&lt;p&gt;76.80.63.158: /* Structures */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Elements of C==&lt;br /&gt;
Sources&lt;br /&gt;
* [http://robertseacord.com/wp/errata/ Effective C ]by Robert Seacord&lt;br /&gt;
* [https://www.oreilly.com/library/view/21st-century-c/9781449344382/ 21st Century C] by Ben Clemens&lt;br /&gt;
* [https://shop.learncodethehardway.org/products/contents/3/ Learn C the Hard Way] by Zed Shaw&lt;br /&gt;
* [https://link.springer.com/book/10.1007/978-1-4842-6128-6 Practical Numerical C Programming] and [https://learning.oreilly.com/library/view/numerical-c-applied/9781484250648/ Numerical C] by Philip Joyce&lt;br /&gt;
* [https://link.springer.com/book/10.1007/978-1-4842-6927-5 Pointers in C Programming] by Thomas Mailund&lt;br /&gt;
* [https://www.packtpub.com/product/learn-c-programming-second-edition/9781801078450 Learn C Programming] by Jeff Szuhay&lt;br /&gt;
* [https://www.packtpub.com/product/practical-c-programming/9781838641108 Practical C Programming] by B.M. Harwani&lt;br /&gt;
* [https://github.com/Apress/practical-c Practical C] by Giulio Zambon (2016) &lt;br /&gt;
&lt;br /&gt;
===Basics===&lt;br /&gt;
From ''Effective C'' by Robert Seacord&lt;br /&gt;
;Objects, Functions, Types and Pointers&lt;br /&gt;
* '''object''': storage used to represent values. (Per ISO/IEC 9989:2018: &amp;quot;a region of data storage in the execution environment, the contents of which can represent values.  A '''variable''' is an example of an object. An object with '''type''' &amp;lt;code&amp;gt;int&amp;lt;/code&amp;gt; contains and integer value. E.g. why types are important: the ''text'' number 1 in IEEE 754 (ASCII, roughly) is specified by 0x3f80000, which a little over a billion as a decimal. &lt;br /&gt;
* '''functions''': are not objects, but do have types. A function is defined by both its return type and the number and types of its parameters. &lt;br /&gt;
* '''types''': &amp;lt;code&amp;gt;int, char, bool, float, long int...&amp;lt;/code&amp;gt;&lt;br /&gt;
* '''pointers''': an address or location in memory where an object or function is stored. Pointer types derive from the ''referenced'' function. or object type. E.g., &amp;lt;code&amp;gt;*char&amp;lt;/code&amp;gt; is called a ''pointer to char''. &lt;br /&gt;
* Because objects and functions are different things, object pointers differ from function pointers&lt;br /&gt;
* In the swap program below the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; function declares two variables of type &amp;lt;code&amp;gt;int&amp;lt;/code&amp;gt;, using the combination of a type (int), an identifier (a,b) and a value (21,17). Assigning the values is also called ''initialization&lt;br /&gt;
&lt;br /&gt;
* '''parameters''': objects declared as part of a function declaration that acquire value on entry to the function&lt;br /&gt;
* '''argruments''': comma-separated expressions included in the function call expression (whether values or pointers)&lt;br /&gt;
* '''pass-by-value''': C's default behavior. When you provide an argument to a function, its value is copied into a distinct variable for use within that function. When the values of the parameters are changed, the values in the caller are unaffected because they are distinct objects.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=C&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
void swap(int *pa, int *pb) {&lt;br /&gt;
  int t = *pa;&lt;br /&gt;
  *pa = *pb;&lt;br /&gt;
  *pb = t;&lt;br /&gt;
  //  int t = a;&lt;br /&gt;
  //a = b;&lt;br /&gt;
  //b = t;&lt;br /&gt;
  printf(&amp;quot;swap: a = %d, b = %d\n&amp;quot;, *pa,*pb);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int main(void){&lt;br /&gt;
  int a = 21;&lt;br /&gt;
  int b = 17; &lt;br /&gt;
  swap(&amp;amp;a, &amp;amp;b);&lt;br /&gt;
  printf(&amp;quot;main: a = %d, b = %d\n&amp;quot;, a, b);&lt;br /&gt;
  &lt;br /&gt;
  return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
&lt;br /&gt;
* The commented lines in the &amp;lt;code&amp;gt;swap&amp;lt;/code&amp;gt; function show the original program, which failed to swap &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;'s values, because they were being passed by value rather than reference. The corrected version (above) declares and dereferences pointers with the '''indirection''' operator (*)&lt;br /&gt;
* In the new version, the line &amp;lt;code&amp;gt;*pa=*pb&amp;lt;/code&amp;gt; serves to: &lt;br /&gt;
# deference the pointer &amp;lt;code&amp;gt;pb&amp;lt;/code&amp;gt;&lt;br /&gt;
# reads the referenced value&lt;br /&gt;
# dereference the pointer &amp;lt;code&amp;gt;pa&amp;lt;/code&amp;gt; &lt;br /&gt;
# overwrite the value at the location referenced by &amp;lt;code&amp;gt;pa&amp;lt;/code&amp;gt; with the value referenced by &amp;lt;code&amp;gt;pb&amp;lt;/code&amp;gt; &lt;br /&gt;
* in the main function, &amp;lt;code&amp;gt;&amp;amp;a&amp;lt;/code&amp;gt; , the unary &amp;amp; operator (''address-of'' operator) generates a pointer to its operand. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=C&amp;gt;&lt;br /&gt;
void increment(void) {&lt;br /&gt;
  static unsigned int counter = 0;&lt;br /&gt;
  counter++; &lt;br /&gt;
  printf(&amp;quot;%d&amp;quot;, counter);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int main(void) {&lt;br /&gt;
  for (int i = 0; i &amp;lt; 5; i++) {&lt;br /&gt;
    increment();&lt;br /&gt;
  }&lt;br /&gt;
  return 0; &lt;br /&gt;
} &lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* '''Scope/Lifetime''': scope applies to identifiers, lifetime applies to objects&lt;br /&gt;
* '''Storage duration''': automatic, static, thread, allocated&lt;br /&gt;
* '''Alignment''': object types have restrictions on the addresses at which they may be stored. an ''alignment'' is the number of bytes between successive addresses at which a given object can be allocated. Traditionally done with linker commands or overallocating memory with &amp;lt;code&amp;gt;malloc&amp;lt;/code&amp;gt;, followed by rounding the address up to nearest power of 2. &lt;br /&gt;
* C11 sorted most of this out. Alignments are values of type &amp;lt;code&amp;gt;size_t&amp;lt;/code&amp;gt;. Valid assignments are non-negative powers of 2. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=C&amp;gt;&lt;br /&gt;
struct S {&lt;br /&gt;
  int i; double d; char c;&lt;br /&gt;
};&lt;br /&gt;
int main(void) {&lt;br /&gt;
  unsigned char bad_buff[sizeof(struct S)];&lt;br /&gt;
  _Alignas(struct S) unsigned char good_buff[sizeof(struct S)];&lt;br /&gt;
  struct S *bad_s_ptr = (struct S *)bad_buff;   // wrong pointer alignment&lt;br /&gt;
  struct S *good_s_ptr = (struct S *)good_buff; // correct pointer alignment&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above code &lt;br /&gt;
&lt;br /&gt;
;Object Types&lt;br /&gt;
* Boolean: declare as &amp;lt;code&amp;gt;bool&amp;lt;/code&amp;gt;; contains either 0 or 1. (Also denoted &amp;lt;code&amp;gt;_Bool&amp;lt;/code&amp;gt;&lt;br /&gt;
* Character: &amp;lt;code&amp;gt; char, signed char, unsigned char&amp;lt;/code&amp;gt;&lt;br /&gt;
* Numeric: &amp;lt;code&amp;gt;signed char, short int, int, long, long long int&amp;lt;/code&amp;gt;. For each there is a corresponding unsigned type that uses the same amount of storage (but obviously only 1/2 the range on the positive side). &lt;br /&gt;
* Enumerations: allows type definition by assigning names (&amp;quot;enumerators&amp;quot;) to integer values. E.g., {S,M,T,W,Th,F,Sa}&lt;br /&gt;
* Floating-point: &amp;lt;code&amp;gt;float, double, long double&amp;lt;/code&amp;gt;. &lt;br /&gt;
* void: the keyword &amp;lt;code&amp;gt;void&amp;lt;/code&amp;gt; means &amp;quot;cannot hold any value&amp;quot;. However, &amp;lt;code&amp;gt;void *&amp;lt;/code&amp;gt; means the pointer can reference ''any'' object. &lt;br /&gt;
;Function Types&lt;br /&gt;
* types are all derived. Name and return type are specified by the ''function declarator''. Parameter types must be specified unless of type &amp;lt;code&amp;gt;void&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=C&amp;gt;&lt;br /&gt;
int max(int a, int b)&lt;br /&gt;
{ return a &amp;gt; b ? a : b; }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* Here is a function that returns an &amp;lt;code&amp;gt;int&amp;lt;/code&amp;gt;. The declarator is &amp;lt;code&amp;gt;max(int a, int b)&amp;lt;/code&amp;gt; and the function body is the 2nd line&lt;br /&gt;
* The function specification (line 2) may not include any type qualifiers (e.g., int, char, etc.)&lt;br /&gt;
&lt;br /&gt;
;Derived Types &lt;br /&gt;
pointers, arrays, type definitions, structures and unions&lt;br /&gt;
*'''Pointers''': derived from the function or object it points to, which is the ''referenced'' type. E.g., &amp;lt;code&amp;gt;int i= 17; int *ip = &amp;amp;i;&amp;lt;/code&amp;gt;, &lt;br /&gt;
declares the variable &amp;lt;code&amp;gt;ip&amp;lt;/code&amp;gt; as a pointer to int and assigns it the address of i. '''The unary * operator converts a pointer to a type into a value of that type.''' Consider &amp;lt;code&amp;gt;ip = &amp;amp;*ip;&amp;lt;/code&amp;gt;. Here * is ''dereferencing'' &amp;lt;code&amp;gt;ip&amp;lt;/code&amp;gt;. It takes the address using &amp;amp; and retrieves the pointer. &lt;br /&gt;
* '''Arrays''': contiguously allocated sequence of objects of the same type. E.g. &amp;lt;code&amp;gt;int ia[11], float *afp[17];&amp;lt;/code&amp;gt;. To declare a matrix, use something like &amp;lt;code&amp;gt;int arr[3][5];&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=C&amp;gt;&lt;br /&gt;
void func(int arr[5]);&lt;br /&gt;
int main(void) {&lt;br /&gt;
  unsigned int i = 0;&lt;br /&gt;
  unsigned int j = 0;&lt;br /&gt;
  int arr[3][5];&lt;br /&gt;
  u func(arr[i]);&lt;br /&gt;
  v int x = arr[i][j];&lt;br /&gt;
  return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
What's happening? &lt;br /&gt;
When the function calls &amp;lt;code&amp;gt;arr[i]&amp;lt;/code&amp;gt;, a bunch of shit happens:&lt;br /&gt;
# &amp;lt;code&amp;gt;arr&amp;lt;/code&amp;gt; is converted to a pointer to the initial 5-element int array, starting at &amp;lt;code&amp;gt;arr[i]&amp;lt;/code&amp;gt;&lt;br /&gt;
# &amp;lt;code&amp;gt;i&amp;lt;/code&amp;gt; is scaled to the type of &amp;lt;code&amp;gt;arr&amp;lt;/code&amp;gt; by multiplying it by the size of one array of 5 int objects&lt;br /&gt;
# The results from the above are added&lt;br /&gt;
# Indirection is applied to the result to produce an array of 5 int elements&lt;br /&gt;
&lt;br /&gt;
====Structures====&lt;br /&gt;
* contain sequentially allocated memory objects&lt;br /&gt;
* objects have their own names and may or may not share the same type (unlike arrays, which are monotyyped); similar to records&lt;br /&gt;
* below, the structure contains 3 objects, &amp;lt;code&amp;gt;signum, signame, sigdesc&amp;lt;/code&amp;gt;&lt;br /&gt;
* the last line identifies the whole object as &amp;lt;code&amp;gt;sigline&amp;lt;/code&amp;gt; and having a pointer of &amp;lt;code&amp;gt;*sigline_p&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=C&amp;gt;&lt;br /&gt;
struct sigrecord {&lt;br /&gt;
  int signum;&lt;br /&gt;
  char signame[20];&lt;br /&gt;
  char sigdesc[100];&lt;br /&gt;
} sigline, *sigline_p;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Now that the struct has been created we'd like to reference its members, using the &amp;quot;structure member operator (&amp;lt;math&amp;gt;\cdot&amp;lt;/math&amp;gt;&amp;quot;; like the dot operator in Python and other langs). &lt;br /&gt;
*  a pointer to a struct can reference its members with the (-&amp;gt;) structure pointer operator&lt;br /&gt;
* the first 3 lines directly access members of the &amp;lt;code&amp;gt;sigline&amp;lt;/code&amp;gt; object. The middle line assigns its address to the &amp;lt;code&amp;gt;sigline_p&amp;lt;/code&amp;gt; pointer. &lt;br /&gt;
* the last 3 lines indirectly access members of the struct. &lt;br /&gt;
&amp;lt;syntaxhighlight lang=C&amp;gt;&lt;br /&gt;
sigline.signum = 5;&lt;br /&gt;
strcpy(sigline.signame, &amp;quot;SIGINT&amp;quot;);&lt;br /&gt;
strcpy(sigline.sigdesc, &amp;quot;Interrupt from keyboard&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
sigline_p = &amp;amp;sigline;&lt;br /&gt;
&lt;br /&gt;
sigline_p-&amp;gt;signum = 5;&lt;br /&gt;
strcpy(sigline_p-&amp;gt;signame, &amp;quot;SIGINT&amp;quot;);&lt;br /&gt;
strcpy(sigline_p-&amp;gt;sigdesc, &amp;quot;Interrupt from keyboard&amp;quot;);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; Unions&lt;br /&gt;
* Similar to structs, but memory for member objects overlaps&lt;br /&gt;
* Primarily used to conserve memory and used to contain mixed types (e.g., ints and floats)&lt;br /&gt;
* access elements with dot operator; reference members with the -&amp;gt; operator&lt;br /&gt;
&lt;br /&gt;
; Tags &lt;br /&gt;
* naming mechanism for structs, unions and enumerations&lt;br /&gt;
* declare a tag for a struct s: &amp;lt;code&amp;gt;struct s &amp;lt;mytag&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; Type Qualifiers (const, volatile, restrict)&lt;br /&gt;
&lt;br /&gt;
===Arithmetic Types===&lt;/div&gt;</summary>
		<author><name>76.80.63.158</name></author>
	</entry>
	<entry>
		<id>https://btechwiki.duckdns.org/index.php?title=C_language&amp;diff=850</id>
		<title>C language</title>
		<link rel="alternate" type="text/html" href="https://btechwiki.duckdns.org/index.php?title=C_language&amp;diff=850"/>
		<updated>2022-03-24T21:45:12Z</updated>

		<summary type="html">&lt;p&gt;76.80.63.158: /* Structures */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Elements of C==&lt;br /&gt;
Sources&lt;br /&gt;
* [http://robertseacord.com/wp/errata/ Effective C ]by Robert Seacord&lt;br /&gt;
* [https://www.oreilly.com/library/view/21st-century-c/9781449344382/ 21st Century C] by Ben Clemens&lt;br /&gt;
* [https://shop.learncodethehardway.org/products/contents/3/ Learn C the Hard Way] by Zed Shaw&lt;br /&gt;
* [https://link.springer.com/book/10.1007/978-1-4842-6128-6 Practical Numerical C Programming] and [https://learning.oreilly.com/library/view/numerical-c-applied/9781484250648/ Numerical C] by Philip Joyce&lt;br /&gt;
* [https://link.springer.com/book/10.1007/978-1-4842-6927-5 Pointers in C Programming] by Thomas Mailund&lt;br /&gt;
* [https://www.packtpub.com/product/learn-c-programming-second-edition/9781801078450 Learn C Programming] by Jeff Szuhay&lt;br /&gt;
* [https://www.packtpub.com/product/practical-c-programming/9781838641108 Practical C Programming] by B.M. Harwani&lt;br /&gt;
* [https://github.com/Apress/practical-c Practical C] by Giulio Zambon (2016) &lt;br /&gt;
&lt;br /&gt;
===Basics===&lt;br /&gt;
From ''Effective C'' by Robert Seacord&lt;br /&gt;
;Objects, Functions, Types and Pointers&lt;br /&gt;
* '''object''': storage used to represent values. (Per ISO/IEC 9989:2018: &amp;quot;a region of data storage in the execution environment, the contents of which can represent values.  A '''variable''' is an example of an object. An object with '''type''' &amp;lt;code&amp;gt;int&amp;lt;/code&amp;gt; contains and integer value. E.g. why types are important: the ''text'' number 1 in IEEE 754 (ASCII, roughly) is specified by 0x3f80000, which a little over a billion as a decimal. &lt;br /&gt;
* '''functions''': are not objects, but do have types. A function is defined by both its return type and the number and types of its parameters. &lt;br /&gt;
* '''types''': &amp;lt;code&amp;gt;int, char, bool, float, long int...&amp;lt;/code&amp;gt;&lt;br /&gt;
* '''pointers''': an address or location in memory where an object or function is stored. Pointer types derive from the ''referenced'' function. or object type. E.g., &amp;lt;code&amp;gt;*char&amp;lt;/code&amp;gt; is called a ''pointer to char''. &lt;br /&gt;
* Because objects and functions are different things, object pointers differ from function pointers&lt;br /&gt;
* In the swap program below the &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt; function declares two variables of type &amp;lt;code&amp;gt;int&amp;lt;/code&amp;gt;, using the combination of a type (int), an identifier (a,b) and a value (21,17). Assigning the values is also called ''initialization&lt;br /&gt;
&lt;br /&gt;
* '''parameters''': objects declared as part of a function declaration that acquire value on entry to the function&lt;br /&gt;
* '''argruments''': comma-separated expressions included in the function call expression (whether values or pointers)&lt;br /&gt;
* '''pass-by-value''': C's default behavior. When you provide an argument to a function, its value is copied into a distinct variable for use within that function. When the values of the parameters are changed, the values in the caller are unaffected because they are distinct objects.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=C&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
void swap(int *pa, int *pb) {&lt;br /&gt;
  int t = *pa;&lt;br /&gt;
  *pa = *pb;&lt;br /&gt;
  *pb = t;&lt;br /&gt;
  //  int t = a;&lt;br /&gt;
  //a = b;&lt;br /&gt;
  //b = t;&lt;br /&gt;
  printf(&amp;quot;swap: a = %d, b = %d\n&amp;quot;, *pa,*pb);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int main(void){&lt;br /&gt;
  int a = 21;&lt;br /&gt;
  int b = 17; &lt;br /&gt;
  swap(&amp;amp;a, &amp;amp;b);&lt;br /&gt;
  printf(&amp;quot;main: a = %d, b = %d\n&amp;quot;, a, b);&lt;br /&gt;
  &lt;br /&gt;
  return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt; &lt;br /&gt;
&lt;br /&gt;
* The commented lines in the &amp;lt;code&amp;gt;swap&amp;lt;/code&amp;gt; function show the original program, which failed to swap &amp;lt;code&amp;gt;main&amp;lt;/code&amp;gt;'s values, because they were being passed by value rather than reference. The corrected version (above) declares and dereferences pointers with the '''indirection''' operator (*)&lt;br /&gt;
* In the new version, the line &amp;lt;code&amp;gt;*pa=*pb&amp;lt;/code&amp;gt; serves to: &lt;br /&gt;
# deference the pointer &amp;lt;code&amp;gt;pb&amp;lt;/code&amp;gt;&lt;br /&gt;
# reads the referenced value&lt;br /&gt;
# dereference the pointer &amp;lt;code&amp;gt;pa&amp;lt;/code&amp;gt; &lt;br /&gt;
# overwrite the value at the location referenced by &amp;lt;code&amp;gt;pa&amp;lt;/code&amp;gt; with the value referenced by &amp;lt;code&amp;gt;pb&amp;lt;/code&amp;gt; &lt;br /&gt;
* in the main function, &amp;lt;code&amp;gt;&amp;amp;a&amp;lt;/code&amp;gt; , the unary &amp;amp; operator (''address-of'' operator) generates a pointer to its operand. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=C&amp;gt;&lt;br /&gt;
void increment(void) {&lt;br /&gt;
  static unsigned int counter = 0;&lt;br /&gt;
  counter++; &lt;br /&gt;
  printf(&amp;quot;%d&amp;quot;, counter);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int main(void) {&lt;br /&gt;
  for (int i = 0; i &amp;lt; 5; i++) {&lt;br /&gt;
    increment();&lt;br /&gt;
  }&lt;br /&gt;
  return 0; &lt;br /&gt;
} &lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* '''Scope/Lifetime''': scope applies to identifiers, lifetime applies to objects&lt;br /&gt;
* '''Storage duration''': automatic, static, thread, allocated&lt;br /&gt;
* '''Alignment''': object types have restrictions on the addresses at which they may be stored. an ''alignment'' is the number of bytes between successive addresses at which a given object can be allocated. Traditionally done with linker commands or overallocating memory with &amp;lt;code&amp;gt;malloc&amp;lt;/code&amp;gt;, followed by rounding the address up to nearest power of 2. &lt;br /&gt;
* C11 sorted most of this out. Alignments are values of type &amp;lt;code&amp;gt;size_t&amp;lt;/code&amp;gt;. Valid assignments are non-negative powers of 2. &lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=C&amp;gt;&lt;br /&gt;
struct S {&lt;br /&gt;
  int i; double d; char c;&lt;br /&gt;
};&lt;br /&gt;
int main(void) {&lt;br /&gt;
  unsigned char bad_buff[sizeof(struct S)];&lt;br /&gt;
  _Alignas(struct S) unsigned char good_buff[sizeof(struct S)];&lt;br /&gt;
  struct S *bad_s_ptr = (struct S *)bad_buff;   // wrong pointer alignment&lt;br /&gt;
  struct S *good_s_ptr = (struct S *)good_buff; // correct pointer alignment&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the above code &lt;br /&gt;
&lt;br /&gt;
;Object Types&lt;br /&gt;
* Boolean: declare as &amp;lt;code&amp;gt;bool&amp;lt;/code&amp;gt;; contains either 0 or 1. (Also denoted &amp;lt;code&amp;gt;_Bool&amp;lt;/code&amp;gt;&lt;br /&gt;
* Character: &amp;lt;code&amp;gt; char, signed char, unsigned char&amp;lt;/code&amp;gt;&lt;br /&gt;
* Numeric: &amp;lt;code&amp;gt;signed char, short int, int, long, long long int&amp;lt;/code&amp;gt;. For each there is a corresponding unsigned type that uses the same amount of storage (but obviously only 1/2 the range on the positive side). &lt;br /&gt;
* Enumerations: allows type definition by assigning names (&amp;quot;enumerators&amp;quot;) to integer values. E.g., {S,M,T,W,Th,F,Sa}&lt;br /&gt;
* Floating-point: &amp;lt;code&amp;gt;float, double, long double&amp;lt;/code&amp;gt;. &lt;br /&gt;
* void: the keyword &amp;lt;code&amp;gt;void&amp;lt;/code&amp;gt; means &amp;quot;cannot hold any value&amp;quot;. However, &amp;lt;code&amp;gt;void *&amp;lt;/code&amp;gt; means the pointer can reference ''any'' object. &lt;br /&gt;
;Function Types&lt;br /&gt;
* types are all derived. Name and return type are specified by the ''function declarator''. Parameter types must be specified unless of type &amp;lt;code&amp;gt;void&amp;lt;/code&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=C&amp;gt;&lt;br /&gt;
int max(int a, int b)&lt;br /&gt;
{ return a &amp;gt; b ? a : b; }&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
* Here is a function that returns an &amp;lt;code&amp;gt;int&amp;lt;/code&amp;gt;. The declarator is &amp;lt;code&amp;gt;max(int a, int b)&amp;lt;/code&amp;gt; and the function body is the 2nd line&lt;br /&gt;
* The function specification (line 2) may not include any type qualifiers (e.g., int, char, etc.)&lt;br /&gt;
&lt;br /&gt;
;Derived Types &lt;br /&gt;
pointers, arrays, type definitions, structures and unions&lt;br /&gt;
*'''Pointers''': derived from the function or object it points to, which is the ''referenced'' type. E.g., &amp;lt;code&amp;gt;int i= 17; int *ip = &amp;amp;i;&amp;lt;/code&amp;gt;, &lt;br /&gt;
declares the variable &amp;lt;code&amp;gt;ip&amp;lt;/code&amp;gt; as a pointer to int and assigns it the address of i. '''The unary * operator converts a pointer to a type into a value of that type.''' Consider &amp;lt;code&amp;gt;ip = &amp;amp;*ip;&amp;lt;/code&amp;gt;. Here * is ''dereferencing'' &amp;lt;code&amp;gt;ip&amp;lt;/code&amp;gt;. It takes the address using &amp;amp; and retrieves the pointer. &lt;br /&gt;
* '''Arrays''': contiguously allocated sequence of objects of the same type. E.g. &amp;lt;code&amp;gt;int ia[11], float *afp[17];&amp;lt;/code&amp;gt;. To declare a matrix, use something like &amp;lt;code&amp;gt;int arr[3][5];&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=C&amp;gt;&lt;br /&gt;
void func(int arr[5]);&lt;br /&gt;
int main(void) {&lt;br /&gt;
  unsigned int i = 0;&lt;br /&gt;
  unsigned int j = 0;&lt;br /&gt;
  int arr[3][5];&lt;br /&gt;
  u func(arr[i]);&lt;br /&gt;
  v int x = arr[i][j];&lt;br /&gt;
  return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
What's happening? &lt;br /&gt;
When the function calls &amp;lt;code&amp;gt;arr[i]&amp;lt;/code&amp;gt;, a bunch of shit happens:&lt;br /&gt;
# &amp;lt;code&amp;gt;arr&amp;lt;/code&amp;gt; is converted to a pointer to the initial 5-element int array, starting at &amp;lt;code&amp;gt;arr[i]&amp;lt;/code&amp;gt;&lt;br /&gt;
# &amp;lt;code&amp;gt;i&amp;lt;/code&amp;gt; is scaled to the type of &amp;lt;code&amp;gt;arr&amp;lt;/code&amp;gt; by multiplying it by the size of one array of 5 int objects&lt;br /&gt;
# The results from the above are added&lt;br /&gt;
# Indirection is applied to the result to produce an array of 5 int elements&lt;br /&gt;
&lt;br /&gt;
====Structures====&lt;br /&gt;
* contain sequentially allocated memory objects&lt;br /&gt;
* objects have their own names and may or may not share the same type (unlike arrays, which are monotyyped); similar to records&lt;br /&gt;
* below, the structure contains 3 objects, &amp;lt;code&amp;gt;signum, signame, sigdesc&amp;lt;/code&amp;gt;&lt;br /&gt;
* the last line identifies the whole object as &amp;lt;code&amp;gt;sigline&amp;lt;/code&amp;gt; and having a pointer of &amp;lt;code&amp;gt;*sigline_p&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=C&amp;gt;&lt;br /&gt;
struct sigrecord {&lt;br /&gt;
  int signum;&lt;br /&gt;
  char signame[20];&lt;br /&gt;
  char sigdesc[100];&lt;br /&gt;
} sigline, *sigline_p;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Now that the struct has been created we'd like to reference its members, using the &amp;quot;structure member operator (&amp;lt;math&amp;gt;\cdot&amp;lt;/math&amp;gt;&amp;quot;; like the dot operator in Python and other langs). &lt;br /&gt;
*  a pointer to a struct can reference its members with the (-&amp;gt;) structure pointer operator&lt;br /&gt;
* the first 3 lines directly access members of the &amp;lt;code&amp;gt;sigline&amp;lt;/code&amp;gt; object. The middle line assigns its address to the &amp;lt;code&amp;gt;sigline_p&amp;lt;/code&amp;gt; pointer. &lt;br /&gt;
* the last 3 lines indirectly access members of the struct. &lt;br /&gt;
&amp;lt;syntaxhighlight lang=C&amp;gt;&lt;br /&gt;
sigline.signum = 5;&lt;br /&gt;
strcpy(sigline.signame, &amp;quot;SIGINT&amp;quot;);&lt;br /&gt;
strcpy(sigline.sigdesc, &amp;quot;Interrupt from keyboard&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
sigline_p = &amp;amp;sigline;&lt;br /&gt;
&lt;br /&gt;
sigline_p-&amp;gt;signum = 5;&lt;br /&gt;
strcpy(sigline_p-&amp;gt;signame, &amp;quot;SIGINT&amp;quot;);&lt;br /&gt;
strcpy(sigline_p-&amp;gt;sigdesc, &amp;quot;Interrupt from keyboard&amp;quot;);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
; Unions&lt;br /&gt;
; Tags &lt;br /&gt;
; Type Qualifiers (const, volatile, restrict)&lt;br /&gt;
&lt;br /&gt;
===Arithmetic Types===&lt;/div&gt;</summary>
		<author><name>76.80.63.158</name></author>
	</entry>
	<entry>
		<id>https://btechwiki.duckdns.org/index.php?title=Where_was_i&amp;diff=810</id>
		<title>Where was i</title>
		<link rel="alternate" type="text/html" href="https://btechwiki.duckdns.org/index.php?title=Where_was_i&amp;diff=810"/>
		<updated>2022-03-11T20:40:37Z</updated>

		<summary type="html">&lt;p&gt;76.80.63.158: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
* [https://www.freeformatter.com/sql-formatter.html#ad-output SQL text formatter]&lt;br /&gt;
* [https://www.dpriver.com/pp/sqlformat.htm SQL html formatter]&lt;br /&gt;
* [https://learnsql.com/blog/5-tips-managing-long-sql-queries/ Managing long queries]&lt;br /&gt;
* [https://hackr.io/tutorials/learn-mysql?ref=blog MySQL resources]&lt;br /&gt;
* [https://mariadb.org/documentation/#getting-started MariaDB resources]&lt;br /&gt;
* [https://www.mariadbtutorial.com/mariadb-basics/mariadb-update/ MariaDB tutorial]&lt;br /&gt;
* [http://www.norvig.com/21-days.html Peter Norvig's] home page&lt;br /&gt;
* [https://sqlflow.gudusoft.com/#/ SQLFlow visualization tool]&lt;br /&gt;
* [https://pentesttools.net/maskphish-give-a-mask-to-phishing-url/ PenTesting phishing]&lt;/div&gt;</summary>
		<author><name>76.80.63.158</name></author>
	</entry>
	<entry>
		<id>https://btechwiki.duckdns.org/index.php?title=Where_was_i&amp;diff=809</id>
		<title>Where was i</title>
		<link rel="alternate" type="text/html" href="https://btechwiki.duckdns.org/index.php?title=Where_was_i&amp;diff=809"/>
		<updated>2022-03-11T19:48:50Z</updated>

		<summary type="html">&lt;p&gt;76.80.63.158: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;br /&gt;
* [https://www.freeformatter.com/sql-formatter.html#ad-output SQL text formatter]&lt;br /&gt;
* [https://www.dpriver.com/pp/sqlformat.htm SQL html formatter]&lt;br /&gt;
* [https://learnsql.com/blog/5-tips-managing-long-sql-queries/ Managing long queries]&lt;br /&gt;
* [https://hackr.io/tutorials/learn-mysql?ref=blog MySQL resources]&lt;br /&gt;
* [https://mariadb.org/documentation/#getting-started MariaDB resources]&lt;br /&gt;
* [https://www.mariadbtutorial.com/mariadb-basics/mariadb-update/ MariaDB tutorial]&lt;br /&gt;
* [http://www.norvig.com/21-days.html Peter Norvig's] home page&lt;br /&gt;
* [https://sqlflow.gudusoft.com/#/ SQLFlow visualization tool]&lt;br /&gt;
*&lt;/div&gt;</summary>
		<author><name>76.80.63.158</name></author>
	</entry>
</feed>