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

13 12738
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++

1 11363
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++

1 10740
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++

0 10644
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++

8 10340
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++

6 10240
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++

7 10077
Q:

What is the output of this program?

#include
        using namespace std;
        void fun(int x, int y)
        {
            x = 20;
            y = 10;
        }
        int main()
        {
            int x = 10;
            fun(x, x);
            cout << x;
            return 0;
        }

A) 10 B) 20
C) compile time error D) none of these
 
Answer & Explanation Answer: A) 10

Explanation:

In this program, we called by value so the value will not be changed, So the output is 10

Report Error

View Answer Report Error Discuss

Filed Under: C++

0 10071