<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://aznot.com/index.php?action=history&amp;feed=atom&amp;title=C</id>
	<title>C - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://aznot.com/index.php?action=history&amp;feed=atom&amp;title=C"/>
	<link rel="alternate" type="text/html" href="https://aznot.com/index.php?title=C&amp;action=history"/>
	<updated>2026-05-08T16:35:42Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.41.0</generator>
	<entry>
		<id>https://aznot.com/index.php?title=C&amp;diff=2567&amp;oldid=prev</id>
		<title>Kenneth: Created page with &quot;== C Programming Language ==  C Programming Language (2nd Edition) (Prentice Hall Software) (Paperback)] * Note: The definitive C guide.  Has &lt;code&gt;printf(&quot;Hello World\n&quot;);&lt;/c...&quot;</title>
		<link rel="alternate" type="text/html" href="https://aznot.com/index.php?title=C&amp;diff=2567&amp;oldid=prev"/>
		<updated>2015-10-27T20:34:05Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;== C Programming Language ==  C Programming Language (2nd Edition) (Prentice Hall Software) (Paperback)] * Note: The definitive C guide.  Has &amp;lt;code&amp;gt;printf(&amp;quot;Hello World\n&amp;quot;);&amp;lt;/c...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;== C Programming Language ==&lt;br /&gt;
&lt;br /&gt;
C Programming Language (2nd Edition) (Prentice Hall Software) (Paperback)]&lt;br /&gt;
* Note: The definitive C guide.  Has &amp;lt;code&amp;gt;printf(&amp;quot;Hello World\n&amp;quot;);&amp;lt;/code&amp;gt; original example&lt;br /&gt;
&lt;br /&gt;
== C# ==&lt;br /&gt;
&lt;br /&gt;
Are you looking for [[C Sharp]]?&lt;br /&gt;
&lt;br /&gt;
== Hello World ==&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/Hello_world Hello world program - Wikipedia]&lt;br /&gt;
&lt;br /&gt;
 main() {&lt;br /&gt;
   printf(&amp;quot;hello, world\n&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[http://en.wikipedia.org/wiki/The_C_Programming_Language_(book) The C Programming Language (book) - Wikipedia]&lt;br /&gt;
:&amp;quot;Perhaps the most famous example program from the book is its &amp;quot;hello world&amp;quot; program, which just prints out the text &amp;quot;hello, world&amp;quot; to the terminal, as an illustration of a minimal working C program. Numerous texts since then have followed that convention for introducing a programming language.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
== gcc ==&lt;br /&gt;
&lt;br /&gt;
See [[gcc]]&lt;br /&gt;
&lt;br /&gt;
== Code ==&lt;br /&gt;
&lt;br /&gt;
=== Hello World ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
int main() {&lt;br /&gt;
  printf(&amp;quot;Hello World\n&amp;quot;);&lt;br /&gt;
  return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Variables ===&lt;br /&gt;
&lt;br /&gt;
 int i = 1;&lt;br /&gt;
 float f = 1.0;&lt;br /&gt;
 char c = &amp;#039;a&amp;#039;;&lt;br /&gt;
 char s[] = &amp;quot;Hello&amp;quot;;&lt;br /&gt;
 char *p = &amp;quot;Hi&amp;quot;;&lt;br /&gt;
&lt;br /&gt;
=== Print ===&lt;br /&gt;
&lt;br /&gt;
 #include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
 printf(&amp;quot;int:%d  float:%.2f  char:%c  string:%s  string:%s&amp;quot;, i, f, c, s, p);&lt;br /&gt;
&lt;br /&gt;
=== Parameters ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
int main(int argc, char* argv[]) {&lt;br /&gt;
	int i;&lt;br /&gt;
	printf(&amp;quot;CMD Args: %d\n&amp;quot;, argc);&lt;br /&gt;
	for(i = 0 ; i &amp;lt; argc ; i++)&lt;br /&gt;
		printf(&amp;quot;CMD Arg %d = %s\n&amp;quot;, i, argv[i]);  // 0 = ./test&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Array ===&lt;br /&gt;
&lt;br /&gt;
Basic int array, initialization and length&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
int main() {&lt;br /&gt;
	// won&amp;#039;t work for dymanic allocated memory&lt;br /&gt;
	#define ARRAY_LENGTH(x)  (sizeof(x) / sizeof(x[0]))&lt;br /&gt;
	&lt;br /&gt;
	int int_array[10];// = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};&lt;br /&gt;
        // int int_array[10] = { 0 }; // all elements 0&lt;br /&gt;
	// int array_length = sizeof(int_array) / sizeof(int_array[0]);&lt;br /&gt;
	int array_length = ARRAY_LENGTH(int_array);&lt;br /&gt;
	int i;&lt;br /&gt;
	&lt;br /&gt;
	for (i = 0 ; i &amp;lt; array_length ; i++) &lt;br /&gt;
		int_array[i] = i;&lt;br /&gt;
	&lt;br /&gt;
	// 40, 4, 10&lt;br /&gt;
	printf(&amp;quot;total length:%d,  int size:%d,  array length:%d\n&amp;quot;, sizeof(int_array), sizeof(int_array[0]), array_length);&lt;br /&gt;
	for (i = 0 ; i &amp;lt; array_length ; i++)&lt;br /&gt;
		printf(&amp;quot;%d = %d\n&amp;quot;, i, int_array[i]);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note: Arrays are passed as points to functions (Pass by Reference), so modifying an array within a function will modify the original.&lt;br /&gt;
&lt;br /&gt;
Basic char array, initialization and length&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#define ARRAY_LENGTH(x)  (sizeof(x) / sizeof(x[0]))&lt;br /&gt;
&lt;br /&gt;
int ord(char c) { return (unsigned char)c; }&lt;br /&gt;
char chr(int n) { return (unsigned char)n; }&lt;br /&gt;
&lt;br /&gt;
int main() {&lt;br /&gt;
	int i;&lt;br /&gt;
	&lt;br /&gt;
	// SEVERAL WAYS TO INITIALIZE:&lt;br /&gt;
	&lt;br /&gt;
	//char char_array[4] = {&amp;#039;O&amp;#039;, &amp;#039;O&amp;#039;, &amp;#039;O&amp;#039;, &amp;#039;\0&amp;#039;};&lt;br /&gt;
	&lt;br /&gt;
	//char char_array[4] = &amp;quot;OOO&amp;quot;;  // don&amp;#039;t forget ending \0&lt;br /&gt;
	&lt;br /&gt;
	//char char_array[] = &amp;quot;OOO&amp;quot;;  // size is 4 for \0&lt;br /&gt;
	&lt;br /&gt;
	//char char_array[3];&lt;br /&gt;
	&lt;br /&gt;
	//for (i = 0 ; i &amp;lt; ARRAY_LENGTH(char_array) ; i++) &lt;br /&gt;
	//	char_array[i] = &amp;#039;O&amp;#039;;&lt;br /&gt;
	&lt;br /&gt;
	//char char_array[10] = { 0 }; // all elements 0&lt;br /&gt;
	&lt;br /&gt;
	//char char_array[10] = {&amp;#039;O&amp;#039;, &amp;#039;O&amp;#039;};  // auto fills rest with \0, how nice, but can this be trusted?&lt;br /&gt;
	&lt;br /&gt;
	char char_array[10] = {[0 ... 9] = &amp;#039;X&amp;#039;};  // All &amp;#039;X&amp;#039;&lt;br /&gt;
	&lt;br /&gt;
	&lt;br /&gt;
	// int array_length = sizeof(char_array) / sizeof(char_array[0]);&lt;br /&gt;
	int array_length = ARRAY_LENGTH(char_array);&lt;br /&gt;
	&lt;br /&gt;
	&lt;br /&gt;
	// 40, 1, 4&lt;br /&gt;
	printf(&amp;quot;total length:%d,  char size:%d,  array length:%d\n&amp;quot;, sizeof(char_array), sizeof(char_array[0]), array_length);&lt;br /&gt;
	for (i = 0 ; i &amp;lt; array_length ; i++)&lt;br /&gt;
		printf(&amp;quot;%d = %c [%d][%d]\n&amp;quot;, i, char_array[i], char_array[i], ord(char_array[i]));&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
References:&lt;br /&gt;
* How do I determine the size of my array in C? - Stack Overflow - http://stackoverflow.com/questions/37538/how-do-i-determine-the-size-of-my-array-in-c&lt;br /&gt;
* Convert char to int in C and C++ - Stack Overflow - http://stackoverflow.com/questions/5029840/convert-char-to-int-in-c-and-c&lt;br /&gt;
* How to initialize an array in C - Stack Overflow - http://stackoverflow.com/questions/201101/how-to-initialize-an-array-in-c&lt;br /&gt;
&lt;br /&gt;
=== Random ===&lt;br /&gt;
&lt;br /&gt;
FAQ &amp;gt; Generate random numbers? - Cprogramming.com [http://faq.cprogramming.com/cgi-bin/smartfaq.cgi?answer=1042005782&amp;amp;id=1043284385]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;  &lt;br /&gt;
#include &amp;lt;stdlib.h&amp;gt;  &lt;br /&gt;
#include &amp;lt;time.h&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
int main(void)&lt;br /&gt;
{&lt;br /&gt;
  int i;&lt;br /&gt;
  srand(time(NULL));&lt;br /&gt;
  i = rand();&lt;br /&gt;
  printf (&amp;quot;Your random number is %d\n&amp;quot;, i);  &lt;br /&gt;
  printf (&amp;quot;This compiler can generate random numbers from 0 to %d\n&amp;quot;, RAND_MAX);&lt;br /&gt;
  return(0);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Get number between two numbers:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
/*&lt;br /&gt;
   * Formula:  &lt;br /&gt;
   *    rand() % N   &amp;lt;- To get a number between 0 - N-1&lt;br /&gt;
   *    Then add the result to min, giving you &lt;br /&gt;
   *    a random number between min - max.&lt;br /&gt;
   */  &lt;br /&gt;
  rc = (rand() % (max - min + 1) + min);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Pointers ===&lt;br /&gt;
&lt;br /&gt;
Simple int pointer:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
void mod_ptr(int *mptr) {&lt;br /&gt;
	printf(&amp;quot;%d\n&amp;quot;, *mptr);  // 3&lt;br /&gt;
&lt;br /&gt;
	*mptr = 4;&lt;br /&gt;
	printf(&amp;quot;%d\n&amp;quot;, *mptr);  // 4&lt;br /&gt;
	&lt;br /&gt;
	int t = 5;&lt;br /&gt;
	*mptr = t;&lt;br /&gt;
	printf(&amp;quot;%d\n&amp;quot;, *mptr);  // 5&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
int main() {&lt;br /&gt;
	int *ptr;&lt;br /&gt;
	*ptr = 1;&lt;br /&gt;
	printf(&amp;quot;%d\n&amp;quot;, *ptr);  // 1&lt;br /&gt;
	&lt;br /&gt;
	int tmp_num = 2;&lt;br /&gt;
	*ptr = tmp_num;  // get value&lt;br /&gt;
	printf(&amp;quot;%d\n&amp;quot;, *ptr);  // 2&lt;br /&gt;
&lt;br /&gt;
	int tmp_num = 2;&lt;br /&gt;
	ptr = &amp;amp;tmp_num;  // get address&lt;br /&gt;
	printf(&amp;quot;%d\n&amp;quot;, *ptr);  // 2&lt;br /&gt;
&lt;br /&gt;
	*ptr = 3;&lt;br /&gt;
	mod_ptr(ptr);&lt;br /&gt;
	printf(&amp;quot;%d\n&amp;quot;, *ptr);  // 5&lt;br /&gt;
&lt;br /&gt;
	int n;&lt;br /&gt;
	n = *ptr;&lt;br /&gt;
	printf(&amp;quot;%d\n&amp;quot;, n);  // 5&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
References:&lt;br /&gt;
* A Beginner&amp;#039;s Guide to Pointers - CodeProject - http://www.codeproject.com/Articles/627/A-Beginner-s-Guide-to-Pointers&lt;br /&gt;
* Pointers - C++ Documentation - http://www.cplusplus.com/doc/tutorial/pointers/&lt;br /&gt;
&lt;br /&gt;
=== Function Pointers ===&lt;br /&gt;
&lt;br /&gt;
References:&lt;br /&gt;
* The Function Pointer Tutorials - Index - http://www.newty.de/fpt/index.html&lt;br /&gt;
* Function pointer - Wikipedia, the free encyclopedia - https://en.wikipedia.org/wiki/Function_pointer&lt;br /&gt;
&lt;br /&gt;
== C for C++ Programmers ==&lt;br /&gt;
&lt;br /&gt;
Source: [http://people.cs.uchicago.edu/~iancooke/osstuff/ccc.html C for C++ Programmers]&lt;br /&gt;
&lt;br /&gt;
=== Hello World ===&lt;br /&gt;
&lt;br /&gt;
 #include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
 int main() {&lt;br /&gt;
   printf(&amp;quot;Hello World&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
=== Output ===&lt;br /&gt;
&lt;br /&gt;
 printf(&amp;quot;the variable &amp;#039;i&amp;#039; is: %d&amp;quot;, i);&lt;br /&gt;
&lt;br /&gt;
   sequence    type   : produces&lt;br /&gt;
 &lt;br /&gt;
   %d or %i  - int    : signed decimal notation&lt;br /&gt;
   %s        - char * : prints characters until the null character is reached&lt;br /&gt;
   %x        - int    : hexidecimal notation&lt;br /&gt;
   %p        - void * : prints as a pointer &lt;br /&gt;
&lt;br /&gt;
 C++   C&lt;br /&gt;
 cin   stdin&lt;br /&gt;
 cout  stdout&lt;br /&gt;
 cerr  stderr&lt;br /&gt;
&lt;br /&gt;
 int fputs(const char *str, FILE *stream);&lt;br /&gt;
&lt;br /&gt;
 if ( (fputs(&amp;quot;Hello world&amp;quot;, stdout)) == EOF) {&lt;br /&gt;
   fprint(stderr, &amp;quot;Whoops, something went wrong&amp;quot;);&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
=== Input ===&lt;br /&gt;
&lt;br /&gt;
Input is a bit trickier. For reading an entire line you&amp;#039;ll probably want to use fgets(). Here&amp;#039;s the prototype:&lt;br /&gt;
&lt;br /&gt;
  char *fgets(char *buffer, int size, FILE *stream);&lt;br /&gt;
&lt;br /&gt;
fgets() reads up to size-1 characters from stream and stores them in buffer. fgets() stores the null character (&amp;#039;\0&amp;#039;) after the last character read into the buffer and returns &amp;#039;buffer&amp;#039; if everything works fine, or NULL on error or end of file. Here&amp;#039;s an example: &lt;br /&gt;
&lt;br /&gt;
  char *cptr;&lt;br /&gt;
  char buffer[256];&lt;br /&gt;
  &lt;br /&gt;
  printf(&amp;quot;Enter some stuff:\n&amp;quot;);&lt;br /&gt;
  cptr = fgets(buffer, 256, stdin);&lt;br /&gt;
  if(cptr != NULL) {&lt;br /&gt;
    printf(&amp;quot;You typed : %s\n&amp;quot;, cptr);&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
=== Command Line Arguments ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
int main(int argc, char *argv[]) {&lt;br /&gt;
  // argc - count of parameters, include program name&lt;br /&gt;
  // argv - array of arguments, argv[0] is program name&lt;br /&gt;
  if(argc == 2) {&lt;br /&gt;
    printf(&amp;quot;Hello %s\n&amp;quot;, argv[0]);&lt;br /&gt;
  } else {&lt;br /&gt;
    printf(&amp;quot;Usage: %s [name]\n&amp;quot;, argv[0]);&lt;br /&gt;
  }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Memory Allocation ===&lt;br /&gt;
&lt;br /&gt;
  void * malloc(int nbytes)&lt;br /&gt;
&lt;br /&gt;
  /* We&amp;#039;re going to allocate enough space for an integer &lt;br /&gt;
     and assign 5 to that memory location */&lt;br /&gt;
  int *foo;&lt;br /&gt;
  /* malloc call: note the cast of the return value&lt;br /&gt;
     from a void * to the appropriate pointer type */&lt;br /&gt;
  foo = (int *) malloc(sizeof(int));  &lt;br /&gt;
  *foo = 5;&lt;br /&gt;
&lt;br /&gt;
  /* Here we&amp;#039;re allocating space for 5 integers */&lt;br /&gt;
  int *foo;&lt;br /&gt;
  foo = (int *) malloc(sizeof(int) * 5);&lt;br /&gt;
  foo[0] = 17;&lt;br /&gt;
  foo[4] = 22;&lt;br /&gt;
&lt;br /&gt;
  void free(void *);&lt;br /&gt;
&lt;br /&gt;
  free(foo);&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#define SIZE_N 1024*1024 // 1M&lt;br /&gt;
#define SIZE_M 256*37&lt;br /&gt;
&lt;br /&gt;
...&lt;br /&gt;
  char *ptr;&lt;br /&gt;
  if( ( ptr = calloc( SIZE_N, SIZE_M ) ) == NULL ) {&lt;br /&gt;
    printf(&amp;quot;Error allocating memory!\n&amp;quot;);&lt;br /&gt;
    exit(1);&lt;br /&gt;
  }&lt;br /&gt;
  ...&lt;br /&gt;
  free(ptr);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Constants ===&lt;br /&gt;
&lt;br /&gt;
  #define MAX_LEN 1024&lt;br /&gt;
  #define NUM_CALLS 20&lt;br /&gt;
&lt;br /&gt;
=== structs ===&lt;br /&gt;
&lt;br /&gt;
  struct point {&lt;br /&gt;
    int x;&lt;br /&gt;
    int y;&lt;br /&gt;
  };&lt;br /&gt;
&lt;br /&gt;
acceptable usage:&lt;br /&gt;
  struct point p;&lt;br /&gt;
  p.x = 0;&lt;br /&gt;
  p.y = 0;&lt;br /&gt;
&lt;br /&gt;
preferred usage:&lt;br /&gt;
  struct point *p;&lt;br /&gt;
  p = (struct point *) malloc(sizeof(struct point));&lt;br /&gt;
  p-&amp;gt;x = 0;&lt;br /&gt;
  p-&amp;gt;y = 0;&lt;br /&gt;
&lt;br /&gt;
remove struct repetition with typedef:&lt;br /&gt;
  typdef struct point Point;&lt;br /&gt;
  Point *p;&lt;br /&gt;
  p = (Point *) malloc(sizeof(Point);&lt;br /&gt;
  p-&amp;gt;x = 0;&lt;br /&gt;
&lt;br /&gt;
=== Libraries ===&lt;br /&gt;
&lt;br /&gt;
  #include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
  #include &amp;lt;string.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Notes ==&lt;br /&gt;
&lt;br /&gt;
=== printf formatting ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
%[flags][min field width][precision][length]conversion specifier&lt;br /&gt;
  -----  ---------------  ---------  ------ -------------------&lt;br /&gt;
   \             #,*        .#, .*     /             \&lt;br /&gt;
    \                                 /               \&lt;br /&gt;
   #,0,-,+, ,&amp;#039;,I                 hh,h,l,ll,j,z,L    c,d,u,x,X,e,f,g,s,p,%&amp;lt;/b&amp;gt;&lt;br /&gt;
   -------------                 ---------------    -----------------------&lt;br /&gt;
   # | Alternate,                 hh | char,           c | unsigned char,&lt;br /&gt;
   0 | zero pad,                   h | short,          d | signed int,&lt;br /&gt;
   - | left align,                 l | long,           u | unsigned int,&lt;br /&gt;
   + | explicit + - sign,         ll | long long,      x | unsigned hex int,&lt;br /&gt;
     | space for + sign,           j | [u]intmax_t,    X | unsigned HEX int,&lt;br /&gt;
   &amp;#039; | locale thousands grouping,  z | size_t,         e | [-]d.ddde±dd double,&lt;br /&gt;
   I | Use locale&amp;#039;s alt digits     t | ptrdiff_t,      E | [-]d.dddE±dd double,&lt;br /&gt;
                                   L | long double,  ---------=====&lt;br /&gt;
   if no precision   =&amp;gt; 6 decimal places            /  f | [-]d.ddd double,&lt;br /&gt;
   if precision = 0  =&amp;gt; 0 decimal places      _____/   g | e|f as appropriate,&lt;br /&gt;
   if precision = #  =&amp;gt; # decimal places               G | E|F as appropriate,&lt;br /&gt;
   if flag = #       =&amp;gt; always show decimal point      s | string,&lt;br /&gt;
                                             ..............------&lt;br /&gt;
                                            /          p | pointer,&lt;br /&gt;
   if precision      =&amp;gt; max field width    /           % | %&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Source: [http://www.pixelbeat.org/programming/gcc/format_specs.html printf format specifications quick reference]&lt;br /&gt;
&lt;br /&gt;
More at: [http://www.cplusplus.com/reference/clibrary/cstdio/printf/ printf - C++ Reference]&lt;br /&gt;
&lt;br /&gt;
=== malloc vs calloc ===&lt;br /&gt;
&lt;br /&gt;
Conceptually, calloc works like this: [http://www.daniweb.com/forums/thread180535.html#]&lt;br /&gt;
 void *calloc ( size_t n, size_t size ) {&lt;br /&gt;
   void *mem = malloc ( n * size );&lt;br /&gt;
   memset ( mem, 0, n * size );&lt;br /&gt;
   return mem;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
=== Array of pointers ===&lt;br /&gt;
&lt;br /&gt;
Array of pointers: [http://www.roseindia.net/c-tutorials/array-string-using-pointer.shtml]&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include &amp;lt;conio.h&amp;gt;&lt;br /&gt;
void main() {&lt;br /&gt;
  clrscr();&lt;br /&gt;
  char *array[2];&lt;br /&gt;
  array[0]=&amp;quot;Hello&amp;quot;;&lt;br /&gt;
  array[1]=&amp;quot;World&amp;quot;;&lt;br /&gt;
  printf(&amp;quot;The Array of String is = %s,%s\n&amp;quot;, array[0], array[1]);&lt;br /&gt;
  getch();&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== My Code ==&lt;br /&gt;
&lt;br /&gt;
=== fork ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
if(fork())&lt;br /&gt;
	printf(&amp;quot;I am the parent!&amp;quot;); /* A non-zero indicates the parent process */&lt;br /&gt;
else&lt;br /&gt;
	printf(&amp;quot;I am the child!&amp;quot;); /* A zero indicates the child process */&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== parameters ===&lt;br /&gt;
&lt;br /&gt;
=== signals ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Bloat Memory ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#define BLOAT_ARRAY_SIZE 100000  // 10K&lt;br /&gt;
#define BLOAT_SIZE 1024*1024     // 1MB&lt;br /&gt;
&lt;br /&gt;
typedef struct {&lt;br /&gt;
  char bloat[BLOAT_SIZE];&lt;br /&gt;
} bloat_struct;&lt;br /&gt;
&lt;br /&gt;
int main() {&lt;br /&gt;
  bloat_struct *bloat_array[BLOAT_ARRAY_SIZE];  // array of bloated structures&lt;br /&gt;
&lt;br /&gt;
  printf(&amp;quot;Bloat Array Size: %d\n&amp;quot;, BLOAT_ARRAY_SIZE);&lt;br /&gt;
  printf(&amp;quot;Bloat Size: %d\n&amp;quot;, BLOAT_SIZE);&lt;br /&gt;
&lt;br /&gt;
  int i, j;  // loop variables&lt;br /&gt;
  for( i=0 ; i&amp;lt;BLOAT_ARRAY_SIZE ; i++ ) {&lt;br /&gt;
&lt;br /&gt;
    // allocate memory for bloated structure&lt;br /&gt;
    //if( ( bloat_array[i] = (bloat_struct *) malloc( sizeof(bloat_struct) ) ) == NULL )&lt;br /&gt;
    if( ( bloat_array[i] = (bloat_struct *) calloc( sizeof(bloat_struct), 1 ) ) == NULL )&lt;br /&gt;
      printf(&amp;quot;Error allocating bloat: #%d\n&amp;quot;, i);&lt;br /&gt;
&lt;br /&gt;
    // use allocated memory&lt;br /&gt;
    //for( j = 0 ; j&amp;lt;BLOAT_ARRAY_SIZE ; j++ )&lt;br /&gt;
    //      bloat_array[i]-&amp;gt;bloat[j] = &amp;#039;1&amp;#039;;&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  printf(&amp;quot;Memory has been consumed to %d * %d = %.0f bytes.\n&amp;quot;,&lt;br /&gt;
    BLOAT_SIZE, BLOAT_ARRAY_SIZE, (double) BLOAT_SIZE * BLOAT_ARRAY_SIZE);&lt;br /&gt;
  printf(&amp;quot;Press enter to free the memory . . . &amp;quot;);&lt;br /&gt;
&lt;br /&gt;
  char *input;&lt;br /&gt;
  char buff[256];&lt;br /&gt;
  input = fgets(buff, sizeof(buff), stdin);&lt;br /&gt;
&lt;br /&gt;
  // free allocated memory&lt;br /&gt;
  for( i=0 ; i&amp;lt;BLOAT_ARRAY_SIZE ; i++ ) {&lt;br /&gt;
    free(bloat_array[i]);&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Memory consumed: 1073741824&lt;br /&gt;
&lt;br /&gt;
Press enter to free the memory . . .&lt;br /&gt;
[root@adaptecweb ~]# gcc eatmem2.c -o eatmem2 ; if [ $? = 0 ] ; then ./eatmem2 ; fi&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#define BLOAT_ARRAY_SIZE 1024           // 1K&lt;br /&gt;
#define BLOAT_SIZE 1024*1024            // 1MB&lt;br /&gt;
&lt;br /&gt;
int main() {&lt;br /&gt;
        char *bloat_array[BLOAT_ARRAY_SIZE];    // array of pointers&lt;br /&gt;
&lt;br /&gt;
        char buff[1024];        // buffer for readline&lt;br /&gt;
&lt;br /&gt;
        printf(&amp;quot;Object count: %d\n&amp;quot;, BLOAT_ARRAY_SIZE);&lt;br /&gt;
        printf(&amp;quot;Object size:: %d\n&amp;quot;, BLOAT_SIZE);&lt;br /&gt;
        printf(&amp;quot;Memory consumed: %.0f\n&amp;quot;, (double) BLOAT_SIZE * BLOAT_ARRAY_SIZE);&lt;br /&gt;
        printf(&amp;quot;\n&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
        int i, j;       // loop variables&lt;br /&gt;
                if( ( bloat_array[0] = calloc( BLOAT_SIZE, BLOAT_ARRAY_SIZE ) ) == NULL )&lt;br /&gt;
                        printf(&amp;quot;Error!&amp;quot;);&lt;br /&gt;
        /*&lt;br /&gt;
for( i=0 ; i&amp;lt;BLOAT_ARRAY_SIZE ; i++ ) {&lt;br /&gt;
                // allocate and zero fill memory for each object&lt;br /&gt;
                if( ( bloat_array[i] = calloc( BLOAT_SIZE, 1 ) ) == NULL )&lt;br /&gt;
                        printf(&amp;quot;Error allocating memory! (#%d)\n&amp;quot;, i);&lt;br /&gt;
        }&lt;br /&gt;
*/&lt;br /&gt;
        printf(&amp;quot;Press enter to free the memory . . . &amp;quot;);&lt;br /&gt;
        fgets(buff, sizeof(buff), stdin);&lt;br /&gt;
&lt;br /&gt;
        free(bloat_array[0]);&lt;br /&gt;
        return 0;&lt;br /&gt;
&lt;br /&gt;
        // free allocated memory&lt;br /&gt;
        for( i=0 ; i&amp;lt;BLOAT_ARRAY_SIZE ; i++ ) {&lt;br /&gt;
                free(bloat_array[i]);&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        //printf(&amp;quot;Press enter to free the exit . . . &amp;quot;);&lt;br /&gt;
        //fgets(buff, sizeof(buff), stdin);&lt;br /&gt;
&lt;br /&gt;
        return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#define BLOAT_ARRAY_SIZE 1024           // 1K&lt;br /&gt;
#define BLOAT_SIZE 1024*1024            // 1MB&lt;br /&gt;
&lt;br /&gt;
int main() {&lt;br /&gt;
        char *bloat_array[BLOAT_ARRAY_SIZE];    // array of pointers&lt;br /&gt;
&lt;br /&gt;
        char buff[1024];        // buffer for readline&lt;br /&gt;
&lt;br /&gt;
        printf(&amp;quot;Object count: %d\n&amp;quot;, BLOAT_ARRAY_SIZE);&lt;br /&gt;
        printf(&amp;quot;Object size:: %d\n&amp;quot;, BLOAT_SIZE);&lt;br /&gt;
        printf(&amp;quot;Memory consumed: %.0f\n&amp;quot;, (double) BLOAT_SIZE * BLOAT_ARRAY_SIZE);&lt;br /&gt;
        printf(&amp;quot;\n&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
        int i, j;       // loop variables&lt;br /&gt;
        for( i=0 ; i&amp;lt;BLOAT_ARRAY_SIZE ; i++ ) {&lt;br /&gt;
                // allocate and zero fill memory for each object&lt;br /&gt;
                if( ( bloat_array[i] = calloc( BLOAT_SIZE, 1 ) ) == NULL )&lt;br /&gt;
                        printf(&amp;quot;Error allocating memory! (#%d)\n&amp;quot;, i);&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        printf(&amp;quot;Press enter to free the memory . . . &amp;quot;);&lt;br /&gt;
        fgets(buff, sizeof(buff), stdin);&lt;br /&gt;
&lt;br /&gt;
        // free allocated memory&lt;br /&gt;
        for( i=0 ; i&amp;lt;BLOAT_ARRAY_SIZE ; i++ ) {&lt;br /&gt;
                free(bloat_array[i]);&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        //printf(&amp;quot;Press enter to free the exit . . . &amp;quot;);&lt;br /&gt;
        //fgets(buff, sizeof(buff), stdin);&lt;br /&gt;
&lt;br /&gt;
        return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
#define SIZE_N 1024*1024 // 1M&lt;br /&gt;
#define SIZE_M 126*12&lt;br /&gt;
&lt;br /&gt;
int main() {&lt;br /&gt;
        char *ptr;&lt;br /&gt;
&lt;br /&gt;
        printf(&amp;quot;Allocating %.0f bytes.\n&amp;quot;, (double) SIZE_N * SIZE_M);&lt;br /&gt;
        if( ( ptr = calloc( SIZE_N, SIZE_M ) ) == NULL ) {&lt;br /&gt;
                printf(&amp;quot;Error allocating memory!\n&amp;quot;);&lt;br /&gt;
                exit(1);&lt;br /&gt;
        }&lt;br /&gt;
&lt;br /&gt;
        printf(&amp;quot;Press enter to free the memory . . . &amp;quot;);&lt;br /&gt;
        char buff[1024];        // buffer for readline&lt;br /&gt;
        fgets(buff, sizeof(buff), stdin);&lt;br /&gt;
&lt;br /&gt;
        // free allocated memory&lt;br /&gt;
        free(ptr);&lt;br /&gt;
&lt;br /&gt;
        return 0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== keywords ==&lt;br /&gt;
&lt;br /&gt;
[[Category:Programming]]&lt;/div&gt;</summary>
		<author><name>Kenneth</name></author>
	</entry>
</feed>