This post will focus on the well-known language C. They are valid in C++ too, of course ūüôā

Syntax

// Functions
int add(int term1, int term2)
{
    return (term1 + term2);
}

// Includes
#include "xyz.h"
#include <io.h> // searching in default path of the compiler

// Conditions (Boolean)
a==b    // equal to
a!=b    // not equal to
a>b     // greater than
a<b     // less than
a>=b    // greater than or equal to
a<=b    // less than or equal to

// Control Statements
if(zahl==5)
{
    printf("fiven");
}
else if(zahl==6)
{
    printf("sixn");
}
else
{
    printf("neither five nor sixn");
}

(a > b)?a:b; // Shorthand

switch(a)
{
    case 1: printf("a is onen"); break;
    case 2: printf("a is twon"); break;
    case 3: printf("a is threen"); break;
    default: printf("a ist anythingn"); break;
}

// Loops
break        // cancel loop
continue    // skip this round of loop

for(i=0; i<5; i++)
{
    printf("Number %dn", i+1);
}

while(i <= 100)
{
    printf("Number %dn", i);
    i++;
}

do
{
    printf("nEnter your age: ");
    scanf("%d", &age);
} while(age <  5 || age > 100);

// Variables
int a,b,c;
a=3;
b=5;
c=7;

// Data Types
char    // Characters
short    // Integer -32.767 to +32.768
int        // Integer -2.147.483.647 to +2.147.483.647
long    // Integer -9.223.372.036.854.775.807 to +9.223.372.036.854.775.807
float    // 32 bit
double    // 64 bit

// Misc.
int cube[2][2][2]; // Multi-dimensional array
a % b // Modulo
scanf("%d.%d.%d", &day, &month, &year); // Formatted input

// Comments
// Inline
/* Multi-
line */

Template

#include <stdio.h>
#include <stdlib.h>

int main(void)
{

}
Advertisements