Conditionals |
โ |
|
|
Switch Statements |
โ |
|
|
Constants |
โ |
|
|
While Loops |
โ |
|
|
MultiLine Comments |
โ |
|
/* A comment
*/ |
Print() Debugging |
โ |
|
|
Comments |
โ |
|
// A comment |
Message Passing |
โ |
|
|
Line Comments |
โ |
|
// A comment |
Interfaces |
โ |
|
@protocol Printing
-(void) print;
@end |
File Imports |
โ |
|
// #import ensures that a file is only ever included once so that you never have a problem with recursive includes.
#import
#include
#include |
Constructors |
โ |
|
|
Pointers |
โ |
|
|
Single Dispatch |
โ |
|
|
Strings |
โ |
|
"hello world" |
Scientific Notation |
โ |
|
|
Case Sensitivity |
โ |
|
|
Assignment |
โ |
|
|
Increment and decrement operators |
โ |
|
|
Zero-based numbering |
โ |
|
|
Variadic Functions |
โ |
|
double average(int count, ...)
{
//
} |
Manual Memory Management |
โ |
|
#include
#include
int main(void)
{
int *poin = malloc(4);
free(poin);
} |
Macros |
โ |
|
// https://learn.microsoft.com/en-us/cpp/preprocessor/macros-c-cpp?redirectedfrom=MSDN&view=msvc-170
// https://gcc.gnu.org/onlinedocs/cpp/Macro-Arguments.html
#define min(X, Y) ((X) < (Y) ? (X) : (Y))
x = min(a, b); โ x = ((a) < (b) ? (a) : (b));
y = min(1, 2); โ y = ((1) < (2) ? (1) : (2));
z = min(a + 28, *p); โ z = ((a + 28) < (*p) ? (a + 28) : (*p)); |
Integers |
โ |
|
int pldb = 80766866; |
Type Casting |
โ |
|
double da = 3.3;
double db = 3.3;
double dc = 3.4;
int result = (int)da + (int)db + (int)dc; //result == 9 |
Directives |
โ |
|
#include
#define height 10
#ifdef
#endif
#if
#else
#ifndef
#undef
#pragma |
Gotos |
โ |
|
// C/C++ program to check if a number is
// even or not using goto statement
#include
using namespace std;
// function to check even or not
void checkEvenOrNot(int num)
{
if (num % 2 == 0)
goto even; // jump to even
else
goto odd; // jump to odd
even:
cout << num << " is evenn";
return; // return if even
odd:
cout << num << " is oddn";
}
// Driver program to test above function
int main()
{
int num = 26;
checkEvenOrNot(num);
return 0;
} |
Structs |
โ |
|
struct account {
int account_number;
char *first_name;
char *last_name;
float balance;
}; |
Symbol Tables |
โ |
|
// Declare an external function
extern double bar(double x);
// Define a public function
double foo(int count)
{
double sum = 0.0;
// Sum all the values bar(1) to bar(count)
for (int i = 1; i <= count; i++)
sum += bar((double) i);
return sum;
}
// Symbol Table:
// Symbol name|Type|Scope
// bar|function, double|extern
// x|double|function parameter
// foo|function, double|global
// count|int|function parameter
// sum|double|block local
// i|int|for-loop statement |
Bitwise Operators |
โ |
|
int i = 4; /* bit pattern equivalent is binary 100 */
int j = i << 2; /* makes it binary 10000, which multiplies the original number by 4 i.e. 16 */ |
Assert Statements |
โ |
|
#include
int i, a[10];
for (i = 0; i < 10; ++i)
{
assert(0 <= i && i < 10);
a[i] = 10-i;
}
for (i = 0; i < 10; ++i)
{
assert(0 <= i && i < 10);
assert(0 <= a[i] && a[i] < 10);
a[a[i]] = a[i];
} |
Ternary operators |
โ |
|
#include
int main(void) { printf("%d", 1 ? 1 : 0); } |
Characters |
โ |
|
char character = 'P'; |
Booleans |
โ |
|
|
Enums |
โ |
|
enum Gender {
Male,
Female,
}; |
Case Insensitive Identifiers |
X |
|
|
Semantic Indentation |
X |
|
|
Operator Overloading |
X |
|
|
Garbage Collection |
X |
|
|
Fixed Point Numbers |
X |
|
|
Exceptions |
X |
|
|
Classes |
X |
|
|
Access Modifiers |
X |
|
|
Templates |
X |
|
|
Multiple Inheritance |
X |
|
|
Namespaces |
X |
|
|
Regular Expression Syntax Sugar |
X |
|
|
Variable Substitution Syntax |
X |
|
|