Computer Science, asked by booshanrules, 1 year ago

consider the following c++ code snippet and what is the program

Answers

Answered by Anonymous
0


1

Secondary SchoolComputer science6 points

Consider the following C++ code snippet and what is the output of this program

Advertisement

Ask for details FollowReport byDeepadas2311 11.02.2018

Answers

Me · Beginner

Know the answer? Add it here!



ayush579Ace

Output of C++ Program | Set 14

2.6

Predict the output of following C++ program.

Difficulty Level: Rookie

Question 1

#include <iostream> using namespace std; class A { int id; public: A (int i) { id = i; } void print () { cout << id << endl; } }; int main() { A a[2]; a[0].print(); a[1].print(); return 0; } 

There is a compilation error in line “A a[2]”. There is no default constructor in class A. When we write our own parameterzied constructor or copy constructor, compiler doesn’t create the default constructor (See this Gfact). We can fix the error, either by creating a default constructor in class A, or by using the following syntax to initialize array member using parameterzied constructor.

// Initialize a[0] with value 10 and a[1] with 20 A a[2] = { A(10), A(20) } 


booshanrules: Hi Bro thanks for your respone
booshanrules: response*
booshanrules: I am trying to clear this chegg exam but i am unable to clear it please share your whatsapp number will send you the screen shot of the question
booshanrules: Hi Adarsh Please respond here
Similar questions