C++ Questions

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++ - Technology

13 12650
Q:

What is the general syntax for accessing the namespace variable?

A) namespaceid::operator B) namespace,operator
C) namespace#operator D) none of the mentioned
 
Answer & Explanation Answer: A) namespaceid::operator

Explanation:
Report Error

View Answer Report Error Discuss

Filed Under: C++ - Technology

1 11210
Q:

How many types of modularization are there in c++?

A) 4 B) 3
C) 1 D) none of these
 
Answer & Explanation Answer: D) none of these

Explanation:

There are two types of modular programming.They are interface and implementation.

Report Error

View Answer Report Error Discuss

Filed Under: C++ - Technology

6 10126
Q:

Which is also called as abstract class?

A) virtual function B) pure virtual function
C) derived class D) None of these
 
Answer & Explanation Answer: B) pure virtual function

Explanation:

Classes that contain at least one pure virtual function are called as abstract base classes.

Report Error

View Answer Report Error Discuss

Filed Under: C++ - Technology

8 10097
Q:

What is the output of this program ?

       #include
        using namespace std;
        int n(char, int);
        int (*p) (char, int) = n;
        int main()
        {
            (*p)('d', 9);
            p(10, 9);
            return 0;
        }
        int n(char c, int i)
        {
            cout << c <<  i;
            return 0;
        }

A) d99 B) d9d9
C) d9 D) compile time error
 
Answer & Explanation Answer: A) d99

Explanation:

In this program, we have declared the values as integer instead of character, So it is printing as d99 but it will not arise an error.

Report Error

View Answer Report Error Discuss

Filed Under: C++ - Technology

1 9953
Q:

How many kinds of classes are there in c++?

A) 1 B) 2
C) 3 D) 4
 
Answer & Explanation Answer: B) 2

Explanation:

There are two kinds of classes in c++. They are absolute class and concrete class.

Report Error

View Answer Report Error Discuss

Filed Under: C++ - Technology

7 9930
Q:

What is the Standard Template Library?

Answer

A library of container templates approved by the ANSI committee for inclusion in the standard C++ specification. A programmer who then launches into a discussion of the generic programming model, iterators, allocators, algorithms, and such, has a higher than average understanding of the new technology that STL brings to C++ programming

Report Error

View answer Workspace Report Error Discuss

Subject: C++ - Technology
Job Role: Software Architect

2 9871
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 & Explanation Answer: A) 252

Explanation:

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

Report Error

View Answer Report Error Discuss

Filed Under: C++ - Technology

0 9856