Home / MCQ Bank / Computer
Computer Classes And Objects In C Plus Plus

What will be the output of the following C++ code? #include <iostream> using namespace std; class sample1 { float i, j; }; class sample2 { int x, y; public: sample2 (int a, int b) { x = a; y = b; } int result() { return x + y; } }; int main () { sample1 d; sample2 * padd; padd = (sample2*) &d; cout<< padd->result(); return 0; }

Select the best option to verify your answer:
Show Correct Answer
Correct Answer: Option D • runtime error or random number

Related Computer Questions

Which of the following is not an alternate name of exponential search? Which command is used to update all installed gems to their latest versions in Ruby? Choose the correct while loop statement from the following that finds the range where are the element being search is present (x is the element being searched in an array arr of size n)? A subtype entity name should be which of the following? What is the time complexity of the following implementation of linear search on a linked list? #include<stdio.h> #include<stdlib.h> struct Node { int val; struct Node* next; }*head; int linear_search(int value) { struct Node *temp = head->next; while(temp != 0) { if(temp->val == value) return 1; temp = temp->next; } return 0; } int main() { int arr[5] = {1,2,3,4,5}; int n = 5,i; head = (struct Node*)malloc(sizeof(struct Node)); head->next = 0; struct Node *temp; temp = head; for(i=0; i<n; i++) { struct Node *newNode = (struct Node*)malloc(sizeof(struct Node)); newNode->next = 0; newNode->val = arr[i]; temp->next = newNode; temp = temp->next; } int ans = linear_search(-1); if(ans == 1) printf("Found"); else printf("Not found"); return 0; }