Two elements of complex data types are not directly comparable. Consider the student structure defined as below struct Student { int rollNo; char name[25]; char grade; }; Student arr[MAX_NUM_STUDENTS]; Objects of Student type are not directly comparable. To sort array arr, we need to specify how one student compares with another student. If there are […]
How will you find minimum of three integers without using any comparison operator ?
Write a class which will implement the Stack data structure in C++. Give the declaration & definition of the class. Also define the Node. For simplicity, you may assume stack to hold integer data type.
The below C++ code will print “Hello World”. #include <iostream> int main() { cout<<“Hello World”; } Without modifying main function, add code to print “Ritambhara” before “Hello World”. You cannot add/remove any statement to main function
What will be the output of the below C++ program: // Template Function – Not taking class template <class T, int i> int myFun(){ T x = 10; i = 20; } int main(){ fun<int, 4>(); return 0; }
While comparing a variable with a constant (literal) in C/C++ language, which of the two ways of comparison should we use ? if( x == 2 ) … if( ptr == NULL ) … Or if( 2 == x ) … if( NULL == ptr ) … In the first comparison we are writing variable […]
Object of a class can be created dynamically on heap or statically on Stack or Data Area. If we have a class MyClass, then the below objects will be created on heap. // Operator: New MyClass *ptr1 = new MyClass(); // Crating object of MyClass on heap. // Operator: New-Array MyClass *ptr2 = new MyClass[10]; // […]
Write a class, such that user can create its object on heap (using new) but user should not be able to create its object on stack or data area. i.e if the class is MyClass, then MyClass stackObj; // Should give compile time error. MyClass *heapobj = new MyClass; // This should be OK, & […]
Can we use delete operator on this inside a class member function in C++, something like below: class TestClass { public: void myFunc() { delete this; } };
How will you find the size of a structure in C/C++ language without using sizeof operator. (Note: sum of sizes of all fields of a structure may not be equal to the exact memory allocated to the structure. See, Method-1 in solution).