Skip to content

Instantly share code, notes, and snippets.

Avatar

Ahmed Abdelfattah aabdelfattah

View GitHub Profile
@aabdelfattah
aabdelfattah / assignment.py
Last active Jun 4, 2019
object assignment
View assignment.py
str = 'medium'
@aabdelfattah
aabdelfattah / call-by-value.py
Last active Jun 4, 2019
python pass object reference by value
View call-by-value.py
def modify(arg):
arg = 'hard'
str = 'medium'
modify(str)
print(str) # >> medium
@aabdelfattah
aabdelfattah / call-by-ref.py
Last active Jun 4, 2019
python pass object reference by value
View call-by-ref.py
def modify(arg):
arg += [1]
l = [2]
modify(l)
print(l) # >> [2, 1]
View assignment.cpp
string str = "medium";
View rvalue.cpp
string getName() {
string str = "medium";
return s;
}
// getName() returns an rvalue
string&& name = getName();
View copy.cpp
class Obj {
//default constructor
Obj(int size){
..
}
//copy constructor
Obj(const Obj& other){
..
}
//assignment operator
View move.cpp
class Obj {
...
//move constructor
Obj(const Obj&& other){
..
}
//move assignment operator
Obj& operator= (const Obj&& other){
..
}