Topic | Python | both | JavaScript |
---|---|---|---|
comments | # """ """ |
// /* */ |
|
declaration | my_var = 5 |
var myVar = 5 let myVar = 5 const myVar = 5 |
|
operators | // |
+ - * ** / % |
|
assignment | = += -= *= **= /= %= |
||
deletion | del(my_var) |
delete(myVar) |
|
increment decrement |
++ -- |
||
equivalence | is |
==``!= |
===``!== |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
#define print(s) std::cout << s << std::endl; | |
using String = std::string; // typedef std::string String; // I don't want to using namespace std - I only want to cherry-pick this one definition. | |
class Car { | |
public: | |
String brand; | |
String model; | |
int year; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#define LOG(x) std::cout << x << std::endl; | |
int main() | |
{ | |
char* buffer = new char[8]; | |
int a = 5; | |
void* ptr = &a; | |
LOG(*(int*)ptr); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#define print(s) std::cout << s << std::endl; | |
int increment0(int value) { | |
value++; | |
return value; | |
} | |
void increment1(int& value) { | |
value++; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
struct vector3 { float x, y, z; }; // struct or class, doesn't matter | |
int main() { | |
int value = 5; // allocated on the stack | |
int array[5]; | |
vector3 vector; | |
array[0] = 1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <string> | |
using String = std::string; | |
int main () { | |
try { | |
String my_str = "Yikes"; | |
throw my_str; | |
} | |
catch (String e) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
template <typename T> | |
T square (T x) { | |
return x*x; | |
} | |
int main() { | |
cout << (5<4 ? "T" : "F") << endl; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <vector> | |
void Print(int s) | |
{ | |
std::cout << s << std::endl; | |
} | |
void ForEach(const std::vector<int>& values, void(*func)(int)) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <vector> | |
int main() | |
{ | |
auto square = [](int num){return num*num;}; | |
auto print = [](int s){std::cout << s << std::endl;}; | |
std::vector<int> values = { 0, 1, 2, 3, 4, 5 }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "../CppLibs/Eigen/eigen-3.3.7/Eigen/Dense" | |
#include <iostream> | |
#define print(s) std::cout << s << std::endl //I know, I know. But it's one line and won't break anything. | |
// I thought about using lambdas for print to be nice but it's no bueno, and I'm not using namespace std and I'm not using << explicitly. It's so ugly. now I'm an outlaw using preprocessor commands on a whim. if you don't like it you're going to need to pry my print() function from my cold, dead hands.//auto print = [](std::string s){std::cout << s << std::endl;}; //I know 4 ways to do this now - typedef, define, using, and lambdas. no preprocessor stuff outside of ifndef. I wanted to template the lambda because I want to be able to print anything - but of course the lambda works using function pointers, and templates make multiple functions based on the use case and thus there are multiple function pointers - so of course it doesn't work... But templated lambdas will be introduced in C++20! Excited for this - should be out this mo |
OlderNewer