Tutor profile: Alex M.
Questions
Subject: Python Programming
How does a list differ from a tuple?
Lists in Python are mutable objects: they can be changed after being created. That means new members can be added, removed, or current members modified. Tuples in Python are immutable: they cannot be changed after being created. That means no new elements can be added or removed. However, elements in a tuple can be changed if the elements are mutable.
Subject: Java Programming
What does the static keyword do when used to label a variable within an object?
The static keyword in front of a variable makes the compiler create a single instance of said variable shared between all of the classes that have the variable. For the class shown below, every instance of Object will have the same count variable with the same value. Changing count in one object will change count in all objects. class Object{ static int count = 0; Object() { count++; } } So for the code below, both print statements will print the same value, 2. Object o1 = new Object(); Object o2 = new Object(); System.out.println(o1.count); System.out.println(o2.count);
Subject: C++ Programming
How does pass-by-reference differ from pass-by-value in C++?
Pass-by-reference passes a pointer or memory address of an object/variable into a function. This allows any changes to the object/variable inside the function to remain once it leaves the scope of the function. This can be seen in the function below: void add(int &num1, int &num2) { num += num2; } Pass-by-value passes a copy of the object/variable into a function. This prevents the original object/variable from being inadvertently changed by the function. All changes remain within the scope of the function. This can be seen in the function below: void add(int num1, int num2) { num += num2; }
Contact tutor
needs and Alex will reply soon.