1
Q:

What is the output of this program?

#include
        using namespace std;
        struct sec {
            int a;
            char b;
        };
        int main()
        {
            struct sec s ={25,50};
            struct sec *ps =(struct sec *)&s;
            cout << ps->a << ps->b;
            return 0;
        }

A) 252 B) 253
C) 254 D) 262

Answer:   A) 252



Explanation:

In this program, We are dividing the values of a and b, printing it.

Subject: C++
Q:

What is a container class?

Answer

A class is said to be a container class which is utilized for the purpose of holding objects in memory or persistent media. A generic class plays a role of generic holder. A container class is a good blend of predefined behavior and an interface that is well known. The purpose of container class is to hide the topology for the purpose of objects list maintenance in memory. A container class is known as heterogeneous container, when it contains a set of different objects. A container class is known as homogeneous container when it contains a set of similar objects.

Report Error

View answer Workspace Report Error Discuss

Subject: C++

2 3915
Q:

What are static and dynamic type checking?

Answer

Type checking is the operation on which the arguments that can only be applied for.


Static type checking performs the type checking operation before the execution of the program. To perform this operation, the arguments, expressions, variables must be given a data type.


Dynamic type checking performs the type checking operation at the time of the program execution. To perform this operation, the arguments, expressions, variables must be given a data type.

Report Error

View answer Workspace Report Error Discuss

Subject: C++

2 3212
Q:

What is function prototyping? What are its advantages?

Answer

Function prototyping is a function declaration statement that tells the compiler about the return type of the function and the number as well as type of arguments required by the function at the time of calling it.


Syntax:


return_type function_name( type1 arg1, type 2 arg2, ... );


 


Advantages of function prototype :


- It helps the compiler in determining whether a function is called correctly or not. Each time when a function is called, its calling statement is compared with its prototype. In case of any mismatch, compiler reports an error.


- A function must be defined before calling it. But prototyping allows a function to be called before defining it.

Report Error

View answer Workspace Report Error Discuss

Subject: C++

37 22801
Q:

Explain static and dynamic memory allocation with an example each.

Answer

When amount of memory to be allocated is known beforehand i.e. at the the time of compilation, it is known as Static Memory Allocation. Once the memory is allocated statically, it cannot be deallocated during program run. So it leads to wastage of storage space.


Example:


int A[100];


 


When amount of memory to be allocated is not known beforehand, rather it is determined at the time of program run, it is called Dynamic Memory Allocation. It leads to efficient utilization of storage space.


Example:


cout << " Enter number of elements: ";


cin >> N;


int *A = new int[N]; // dynamic memory allocation

Report Error

View answer Workspace Report Error Discuss

Subject: C++

13 13041
Q:

What are virtual functions?

Answer

Polymorphism is also achieved in C++ using virtual functions. If a function with same name exists in base as well as parent class, then the pointer to the base class would call the functions associated only with the base class. However, if the function is made virtual and the base pointer is initialized with the address of the derived class, then the function in the child class would be called.

Report Error

View answer Workspace Report Error Discuss

Subject: C++

1 3367
Q:

List the advantages of inheritance

Answer

- Inheritence permits code reusability. 


- Reusability saves time in program development. 


- It encourages the reuse of proven and debugged high-quality software which reduces the problems after a system becomes functional.

Report Error

View answer Workspace Report Error Discuss

Subject: C++

0 2173
Q:

Differentiate between realloc() and free().

Answer

- Free() - A block of memory previously allocated by the malloc subroutine is freed by free subroutine. Undefined results come out if the Pointer parameter is not a valid pointer. If the Pointer parameter is a null value, no action will take place.


- Realloc() - This subroutine changes the size of the block of memory pointed to by the Pointer parameter to the number of bytes specified by the Size parameter and returns a new pointer to the block. The pointer specified by the Pointer parameter must be created with the malloc, calloc, or realloc subroutines and should not be deallocated with the free or realloc subroutines. Undefined results show up if the Pointer parameter is not a valid pointer.

Report Error

View answer Workspace Report Error Discuss

Subject: C++

0 3334
Q:

Different access specifiers for the class member in C++

Answer

Access specifiers in C++ determines the scope of the class members.


Public: If a class member is public, it can be used anywhere without the access restrictions.


Private: if a class member is private, it can be used only by the members and friends of class.


Protected: If a class member is protected, it can be used only by the members and friends of class and the members and friends of classes derived from class.

Report Error

View answer Workspace Report Error Discuss

Subject: C++

1 3555