Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

1.

Using 3 Languages study the precedence and associativity rule:


C++
Precedence Rule
PRECEDENCE OPERATOR ASSOCIATIVITY

1 :: Left to Right

2 a++ Left to Right


a--
3 a*b Left to Right
a/b
a%b
4 a+b Left to Right
a-b
5 < Left to Right
<=
>
>=

JAVA
Precedence Rule
PRECEDENCE OPERATOR ASSOCIATIVITY

1 ++ - - Left to Right

2 */% Left to Right

3 +- Left to Right

4 < <= > >= Left to Right

5 == != Left to Right
PYTHON
Precedence Rule
PRECEDENCE OPERATOR ASSOCIATIVITY

1 () Left to Right

2 ** Left to Right

3 *, /, //, % Left to Right

4 +, - Left to Right

5 ==, !=, >, >=, <, <=, is, is Left to Right


not, in, not in

2. Find out languages that have the problem of operator overload


i. C++
ii. ADA
iii. C#
iv. Fortran 96
v. Haskell

3. Find out languages that support short circuiting and find out reasons why the language
may be liked or disliked
Languages that support short circuiting include:
i. C++
ii. C#
iii. Python
Reasons:
i. C++: In C++ short-circuiting occurs while evaluating ‘&&’ (AND) and ‘||'(OR) logical
operators. While evaluating ‘&&’ operator if the left-hand side of ‘&&’ gives false, then
the expression will always yield false irrespective of the value of the right-hand side of
‘&&’, so checking right-hand side of ‘&&’ makes no sense.
ii. C#: It makes our true/false conditions more efficient since not every expression has to be
evaluated. And short-circuiting can even prevent errors because it skips part of the code.
iii. Python: It stops the execution when the truth value of the expression is determined.
Always the expression of evaluation is from left to right.
4. Java Switch and C# switch which do you prefer using design control?
Java switch case is preferable because it is used in Multiple conditions which has different
statements like if-else. Java switch can check only equality of the conditional floating point but
value cant be checked by the switch.
Its syntax
Switch(variable)
{
Case 1:
Statement;
Case 2:
Statement;
Default :
Statement:
}
5. Find out how python,java,C# or C++ handle inheritance.
Programmming Languages Support for Inheritance
Python The child classes in Python also inherits
methods and attributes from the parent class.
Java Inheritance in Java is implemented using
Extend keywords. It is the method to create a
hierarchy between classes by inheriting from
other classes.
C# In C# inheritance allows the user tp create a
new class from an existing class.
The derived class inherits the fie;d and
methods of the base class.
C++ It’s a process in which new classes are created
from existing classes. The new class created
is called “Derived Class” or “Child Class”
and the existing class is known as the “Base
Class or Parent class”, The derived class is
now said to be inherited from the base class.

6. 10 attributes of Object Oriented Programming


a) Inheritance
b) Polymorphism
c) Encapsulation
d) Class
e) Objects
f) Association
g) Method
h) Attributes
i) Dynamic Model
j) Aggregation
k) Cohesion
l) Composition
m) Dynamic Binding.
7. Difference between Python for loop and java For loop
In python we do for loop like:
For i in range (len(nums))
The range function in python has arguments passed by value. So even after you give the
argument variable a new value, the function still holds the on to the argument value that was
passed . For instance, if the argument passed has a value of 25, if the argument is then given a
new value it will still have its original value of 25.
In Java we have
For ( int i = 0 ; i < nums.length; i++)
In java the loop is checking the value of num after every iteration to see when to stop.

8. Give a sharp contrast between pointers and references


A Pointer refers to an address in memory while A reference refers to an object or a value in
memory.

You might also like