Link to home
Start Free TrialLog in
Avatar of kesavan_sridhar
kesavan_sridhar

asked on

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
Avatar of kesavan_sridhar
kesavan_sridhar

ASKER

Adjusted points to 50
ASKER CERTIFIED SOLUTION
Avatar of nietod
nietod

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
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

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)
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:
https://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++!
>> 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?
(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).  
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????
>> 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?  
Thanks a lot to nietod,kangaroo for your

responses