FEW C++ questions

I have a few c++ questions for you.


(1) Is interface is allowed in all platforms of c++ in cludeing msvc?


(2)what is the difference between parameters and argumemts?

(3) What is the reason for using a 3rd argument in command line?


(4)considering the following scenario:

class A with 20 functions and class B with 10 functions and all functions print just a word(They do nothing)

class A and class B both have i int varialbe in them


         Under this circumstance will the object of A and B will occupy same memory?

        DO Methods and classes as such occupy memory?



Also if anybody can suggest a site that gives tricky questions and

diificult problems in c++ it would be great



THANKS          -----sridhar
kesavan_sridharAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

kesavan_sridharAuthor Commented:
Adjusted points to 50
0
nietodCommented:
>> (1) Is interface is allowed in all
>> platforms of c++ in cludeing msvc?
I don't know what you mean by "interface" in this context.  It has many different meanings.  But there is a very good chance that the answer is yes.

>> (2)what is the difference between
>> parameters and argumemts?
Spelling.  :-)

They mean the same thing.

>> (3) What is the reason for using a 3rd
>> argument in command line?
It depends on the program!  Some programs may allow you to specify files to be "worked on" so you can specify any number of file names like

PKZIP ARCHIVENAME FILE1 FILE2 FILE3 ....

It just depends on the program.  What program are you talking about?

>> Under this circumstance will the object of
>> A and B will occupy same memory?
There is no set of circumstances where two seperate objects will ever occupy the same memory, unless they are members of a union--which would be very rare.

>> DO Methods and classes as such occupy memory?
methods (member functions) occupy member.  But usually (always) they do not exist on a object-by-object basis.  That is, if you have two objects of class A, both share the same member functions.

classes don't occupy memory, but OBJECTS of classes do.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
nietodCommented:
Note the EE rules specifically state that you should ask only one question per EE question (unless they are closely related)  This is to prevent problems that may occur where some questions get answered and others done and other forms of dispute that arisse from this.  Each of these questions are small enough and seperate that they could have each been asked as 25pt questions.  (2 and 3 might belong together, I can't tell.)

If you need more help, let me know.
0
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

akalmaniCommented:
HI !!
 If I have ubnderstood u for the 3rd question its the environment variable.
U can set the environment variable in u r program if it is needed
0
kesavan_sridharAuthor Commented:

TO NIETOD


Thanks for your response.

fOR QUESTION1 I want to know whether we can


group virtual functions under a keyword Interface

in c++?

For question4   I meant whether the 2 objects occupy equal memory(same number
of bytes ) and NOT WHETHER THEY OCCUPY THE SAME MEMORY(address locations)
0
KangaRooCommented:
In C++ an 'interface' is as abstract a concept as in texts about OOP, there is no 'interface' keyword or something similar¹.
In C++ an is commonly expressed with so called 'pure-virtual' members:

class ABC
{
   public:
      void virtual Method() = 0;
};

Note the '= 0' behind the declaration, it tells the compiler that the function is 'pure virtual'.
A class that has one or more pure-virtual functions is called an abstract base class. It is not possible to instantiate objects of such a class.
You can however create classes that derive from such an abstract base class:

class ConcreteClass
{
   public:
      void virtual Method(){};
};

A derived class must provide Method before objects of that class can be instantiated.

>> a site that gives tricky questions and
>> diificult problems in c++
Eh, how about:
http://www.experts-exchange.com/Computers/Programming/Languages/C++/
;)
Visit comp.lang.c++.moderated and comp.std.c++

In for a challenge:
http://www.cntc.com/resources/

¹ GCC has a C++ extension called 'signature' but that is non-standard C++!
0
nietodCommented:
>> FOR QUESTION1 I want to know whether we can
>> group virtual functions under a keyword Interface
>> in c++?
I don't know what you mean by that.  Did kangaroo answer that?  

>> I meant whether the 2 objects occupy equal
>> memory(same number  of bytes ) and NOT
>> WHETHER THEY OCCUPY THE SAME
>> MEMORY(address locations)
The C++ standard does not say much about this.  It does say that no class/structure will have have 0 size.  It does say that the data mebers must be stored in the class in the same order that they are declared in (later data members are at higher addresses).  (however when a private/protected/public label is encountered, the order may be dissrupted.)   It says that there may be padding (unused spaces) placed before data members and between any two data members.  If the class has virtual functions and/or virtual base claseses additional data may be stored in the class that is not declared as a data member.

There is no guarantee that I know of that two classes that have the same data members, in the same order, will use the same layout in memory.  However, it is extreemly unlikely that any compiler would ever use a different layout for them.  So I would say that A and B would have the same size and layout on virtually all compilers, but it is not guaranteed.

however, I have to wonder why you even ask?  The standard makes few guarantees about this stuff for a reason, because it shouldn't matter to you, so why do you want to know?
0
SISUCommented:
(1) Is interface is allowed in all platforms of c++ in cludeing msvc?

Ans:
  In C++, there is no term called Interface. In C++, abstract classes are known as Interface(The classes which contain pure virtual functions).


(2)what is the difference between parameters and argumemts?

Ans:

IF a function takes values that is parametes. If some exe file takes function, if we give values there, those become arguments.

Ex:1. If U calling Sin function
  sin(double rad)

Here rad is argument
 2. any values(parameter) to user defined function, then it is parameters.

(3) What is the reason for using a 3rd argument in command line?
 
Ans:
  In command line arguments 3rd argument represents Environment variable that will give entire path.


(4)considering the following scenario:
class A with 20 functions and class B with 10 functions and all functions print just a word(They do nothing)

class A and class B both have i int varialbe in them


        Under this circumstance will the object of A and B will occupy same memory?

        DO Methods and classes as such occupy memory?
Ans:
   Two objects never share the same memory. In this case the objects of both the classes have the same size.

  One thing is methods, never included in the size of the class and class never takes the memory (It's simply an template). After declaring object, then memmory will be allocated for that object(not for the class).  
0
KangaRooCommented:
2) I concur wi nietod, 'parameter' and 'argument' both can be used (though 'argument' seeks more common).
3) Third parameter of commandline?
Obviously every one is refering to the same function to invoke one program rom another. I just wonder which of the many functions? Apparently not a commonly used C function like system, fork, spawn or even CreateProcess????
0
nietodCommented:
>> In C++, there is no term called Interface.
>> In C++, abstract classes are known as
>> Interface(The classes
>> which contain pure virtual functions).
Actually, I think it is the reverse.  The term "interface" is used in many many ways.  Without a context to put it in, we don't know which way you mean.

And abstract class "define" and interface, they aren't an interface.

>> IF a function takes values that is parametes.
>> If some exe file takes function, if we give
>> values there, those
>> become arguments.
The two are interchangable.  

>> In command line arguments 3rd argument
>> represents Environment variable that will
>> give entire path.
You might be on to something here.  Some UNIX and DOS/Windows compilers have a 3rd parameter passed to main().  This is not a command line parameter.  The command-line parameters are passed to main() in the argv array.  But this 3rd parameter is an array of character string pointers that list the environmental variables that the program may use.  The end of the array is indicated by a NULL pointer, I beleive.

This is a non-standard extension to the C++ language.  That is, the language does not specify that this 3rd parameter is to be passed.  (However, it does allow for it, it says that an implimentation may allow main to be called with additional, implimentation defined, parameters.)

>> In this case the objects of both the
>> classes have the same size
How do you know?  
0
kesavan_sridharAuthor Commented:
Thanks a lot to nietod,kangaroo for your

responses
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.