CPP and Internet Technology

You are on page 1of 5

GARGI MEMORIAL INSTITUTE OF TECHNOLOGY

SUBJECT:-C++ and Internet Technology

1. What are the differences between references and pointers?

Both references and pointers can be used to change local variables of one function inside another
function. Both of them can also be used to save copying of big objects when passed as arguments
to functions or returned from functions, to get efficiency gain.
There are following differences between references and pointers.
1) References cannot be NULL. Pointers are often made NULL to indicate that they are not
pointing to any valid thing.
2) A reference must be initialized when declared. There is no such restriction with pointers
Due to the above limitations, references in C++ cannot be used for implementing data structures
like Linked List, Tree, etc. In Java, references don’t have above restrictions, and can be used to
implement all data structures. References being more powerful in Java, is the main reason Java
doesn’t need pointers.
2.What are virtual functions ?

Virtual functions are used with inheritance, they are called according to the type of object
pointed or referred, not according to the type of pointer or reference. In other words, virtual
functions are resolved late, at runtime. Virtual keyword is used to make a function virtual.

3. What are C++ access specifiers ?


Access specifiers are used to define how the members (functions and variables) can be accessed
outside the class.
 Private: Members declared as private are accessible only within the same class and they
cannot be accessed outside the class they are declared. Child classes are also not allowed to
access private members of parent.
 Public: Members declared as public are accessible from anywhere.
 Protected: Only the class and its child classes can access protected members.

4. Friend class and function in C++

A friend class can access private and protected members of other class in which it is declared as
friend. It is sometimes useful to allow a particular class to access private members of other class.
For example a LinkedList class may be allowed to access private members of Node.
Friend Function Like friend class, a friend function can be given special grant to access private
and protected members. A friend function can be:
a) A method of another class
b) A global function
Important points about friend functions and classes:
1) Friends should be used only for limited purpose. too many functions or external
classes are declared as friends of a class with protected or private data, it lessens the
value of encapsulation of separate classes in object-oriented programming.
2) Friendship is not mutual. If a class A is friend of B, then B doesn’t become friend of A
automatically.
3) Friendship is not inherited (See this for more details)
4) The concept of friends is not there in Java.

5. Function overloading VS Operator Overloading

Function overloading is a feature in C++ where two or more functions can have the same name
but different type of parameters and different number of parameters.
Operating overloading allows us to make operators to work for user defined classes. For
example, we can overload an operator ‘+’ in a class like String so that we can concatenate two
strings by just using +.
Other example classes where arithmetic operators may be overloaded are Complex Number,
Fractional Number, Big Integer, etc.

6. Copy Constructor

A copy constructor is a member function which initializes an object using another object of the
same class. A copy constructor has the following general function prototype: ClassName (const
ClassName &old_obj);
Point(int x1, int y1) { x = x1; y = y1; }
// Copy constructor
Point(const Point &p2) {x = p2.x; y = p2.y; }
When is copy constructor called?
In C++, a Copy Constructor may be called in following cases:
1. When an object of the class is returned by value.
2. When an object of the class is passed (to a function) by value as an argument.
3. When an object is constructed based on another object of the same class.
4. When compiler generates a temporary object.

7.What Is Inheritance?

Different kinds of objects often have a certain amount in common with each other. Yet each also
defines additional features that make them different. Object-oriented programming allows
classes to inherit commonly used state and behavior from other classes
8.What is a class?
Class is a blue print which reflects the entities attributes and actions. Technically defining a class
is designing an user defined data type.

9.What is an object?
An instance of the class is called as object.

10. List the types of inheritance supported in C++.


Single, Multilevel, Multiple, Hierarchical and Hybrid.

11.What is negative infinity?


Negative Infinity is a number in JavaScript which can be derived by dividing negative number
by zero.

12.Explain the working of timers in JavaScript? Also elucidate the drawbacks of using the
timer, if any?

Timers are used to execute a piece of code at a set time or also to repeat the code in a given
interval of time. This is done by using the functions setTimeout, setInterval and clearInterval.

The setTimeout(function, delay) function is used to start a timer that calls a particular function
after the mentioned delay. The setInterval(function, delay)function is used to repeatedly
execute the given function in the mentioned delay and only halts when cancelled.
The clearInterval(id) function instructs the timer to stop.

Timers are operated within a single thread, and thus events might queue up, waiting to be
executed.

13. What is === operator?

=== is called as strict equality operator which returns true when the two operands are having the
same value without any type conversion.

14.Explain how to read and write a file using JavaScript?

There are two ways to read and write a file using JavaScript

 Using JavaScript extensions


 Using a web page and Active X objects
15. What are the different types of errors in JavaScript?

There are three types of errors:

 Load time errors: Errors which come up when loading a web page like improper syntax
errors are known as Load time errors and it generates the errors dynamically.
 Run time errors: Errors that come due to misuse of the command inside the HTML
language.
 Logical Errors: These are the errors that occur due to the bad logic performed on a
function which is having different operation.

16.What is the way to get the status of a CheckBox?

 The status can be acquired as follows -


 alert(document.getElementById('checkbox1').checked);
 If the CheckBox will be checked, this alert will return TRUE.

17. Your router has the following IP address on Ethernet0: 172.16.2.1/23. Which of the
following can be valid host IDs on the LAN interface attached to the router?

1. 172.16.1.100
2. 172.16.1.198
3. 172.16.2.255
4. 172.16.3.0
Ans- 3 and 4

18.What is the maximum number of IP addresses that can be assigned to hosts on a local
subnet that uses the 255.255.255.224 subnet mask?

Ans-30

19.You have an interface on a router with the IP address of 192.168.192.10/29. Including


the router interface, how many hosts can have IP addresses on the LAN attached to the
router interface?

Ans-6

20.You need to configure a server that is on the subnet 192.168.19.24/29. The router has the
first available host address. Which of the following should you assign to the server?
a. 192.168.19.0 255.255.255.0

b. 192.168.19.33 255.255.255.240

c. 192.168.19.26 255.255.255.248

d. 192.168.19.31 255.255.255.248
Ans-C

You might also like