Question


The primary difference between classes and structures is that classes can have functions in them while structures cannot. O T

0 0
Add a comment Improve this question Transcribed image text
Answer #1

False because we can write functions in structures also..

Here is the example to illustrate the above statement..

CODE:

#include<iostream>
using namespace std;
struct person
{
   int debit,salary,profit;
   void sub()  
   {
       debit=10;
       salary=15;
       profit=salary-debit;  
       cout<<profit<<endl;
   }
}obj;

int main()
{
   obj.sub();  
   obj.debit=20;
   cout<<obj.debit<<endl;
   return 0;
}

OUTPUT:

C:\Program Files (x86)\Dev-Cpp ConsolePauser.exe (globals) I check.cpp i #include<iostream> 2 using namespace std; 3 struct p

If you have any doubts please COMMENT..

If you understand the answer please give THUMBS UP...

Add a comment
Know the answer?
Add Answer to:
The primary difference between classes and structures is that classes can have functions in them while...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT