Show Menu
Cheatography

C-Summer Semester Cheat Sheet (DRAFT) by

Summer Semester

This is a draft cheat sheet. It is a work in progress and is not finished yet.

Console Input/­­Output

include <st­dio.h>
Characters
getchar()
פונקציה הקולטת תו בודד ומחזירה את ערך האסקי שלו
putcha­r(int)
פונקציה הקולטת מספר ומדפיסה למסך את התו המתאים
Strings
gets(str)
פונקציה אשר קולטת מספר תווים מהמשתמש ומכיסה אותם לתוך מערך.
Altern­ative
puts("s­tri­ng")
פונקציה המקבלת רק משתנה אחד מהכיר בתוכו סטרינג

Condit­­ional (Branc­­hing)

if, else if, else
if(a) b;
Evaluates b if a is true.
if(a){ b; c; }
Evaluates b and c if a is true.
if(a){ b; }else{ c; }
Evaluates b if a is true, c otherwise.
if(a){ b; }else if(c){ d; }else{ e; }
Evaluates b if a is true, otherwise d if c is true, otherwise e.
switch, case, break
switch(a){ case b: c; }
Evaluates c if a equals b.
switch(a){ default: b; }
Evaluates b if a matches no other case.
switch(a){ case b: c; break; case d: e; break; default: f; }
Evaluates c if a equals b, e if a equals d and e otherwise.

Sorting

int main() 
{ 
    int arr[] = {64, 34, 25, 12, 22, 11, 90}; 
    int n = sizeof(arr)/sizeof(arr[0]); 
    bubbleSort(arr, n); 
    printf("Sorted array: \n"); 
    printArray(arr, n); 
    return 0; 
} 

// A function to implement bubble sort 
void bubbleSort(int arr[], int n) 
{ 
   int i, j; 
   for (i = 0; i < n-1; i++)       
  
       // Last i elements are already in place    
       for (j = 0; j < n-i-1; j++)  
           if (arr[j] > arr[j+1]) 
              swap(&arr[j], &arr[j+1]); 
}
Bubble Sort is the simplest sorting algorithm that works by repeatedly swapping the adjacent elements if they are in wrong order.
 

Loops

while
int x = 0; while(x < 10){ x += 2; }
Loop skipped if test condition initially false.
int x = 0;
Declare and initialise integer x.
while(x < 10)
Loop keyword and condition parent­hesis.
{
x += 2;
Loop contents.
}
do while
char c = 'A';
Declare and initialise character c.
do
Loop keyword.
{
c++;
Loop contents.
while(Test condit­ion.);
Loop keyword and condition parent­hesis. Note semicolon.
c != 'Z'
Test condition.
for
int i; for(i = 0; n[i] != '\0'; i++){}
OR
for(int i = 0; n[i] != '\0'; i++){some thing}