C++ Programming - OOPS Concepts - Discussion
Discussion Forum : OOPS Concepts - General Questions (Q.No. 19)
19.
Which of the following approach is adapted by C++?
Discussion:
27 comments Page 2 of 3.
Spjsp said:
1 decade ago
As OOP operates on classes so, if we declare main before it then there will be an error like main() has an object whose associated class is not declared.
Sakshi said:
1 decade ago
C follows top down approach while C++ follows bottom up approach.
In Top Down Approach, first we write the main function, that calls stubs, then subdivide these stubs in smaller stubs until a real work has to be done, that code in the final files.
In Bottom Up approach, Firstly gathering of small components that do basic actions that are required to do the full program work. Then assemble them by custom code, then assemble these parts to write the main method.
In Top Down Approach, first we write the main function, that calls stubs, then subdivide these stubs in smaller stubs until a real work has to be done, that code in the final files.
In Bottom Up approach, Firstly gathering of small components that do basic actions that are required to do the full program work. Then assemble them by custom code, then assemble these parts to write the main method.
Veerendra said:
1 decade ago
Why can't we write main function at the top?
Shrondi said:
1 decade ago
Can anyone explain properly. Thats how its work in C++ and C?
U.B.Somasekar said:
1 decade ago
Actually in C++ the execution as usually starts from main fun but one thing to observe here is the object gets created first inside the main fun which is of class type and class is always present above (top of) the main fun containing members and member fun's.
So during the time of compilation, the objects of main get created that contains separate copies of data members present in the class which is top of main and memory fun's gets shared to all object.
So first the object gets created at bottom and uses the encapsulated data memory's or memory fun's presented inside the class at top.
So during the time of compilation, the objects of main get created that contains separate copies of data members present in the class which is top of main and memory fun's gets shared to all object.
So first the object gets created at bottom and uses the encapsulated data memory's or memory fun's presented inside the class at top.
Balaji Ponmuthu said:
1 decade ago
For C:
In Top Down approach main function should be at the top, ie other function definition are after main.
{..
main()
{...
..}
{ initialization,
Func()
}
For C++:
In bottom up approach we can define main anywhere in our program.
{
Initialization;
Fun()
{
}
}
main(){
..}
In Top Down approach main function should be at the top, ie other function definition are after main.
{..
main()
{...
..}
{ initialization,
Func()
}
For C++:
In bottom up approach we can define main anywhere in our program.
{
Initialization;
Fun()
{
}
}
main(){
..}
Ashik said:
1 decade ago
It just follows the bottom-up approach. Not compulsory that it may go bottom-up any time.
U.B.Somasekar said:
1 decade ago
Always the class should under the global region. i.e.above main.
Saurabh said:
10 years ago
So, java and c# both follow bottom up approach, right?
Sourav Pathak said:
10 years ago
Guys, there is nothing related with main function. Some say that since in c++ program starts executing from main function, so C++ is a bottom up approach.
I was asked the same question in TCS interview and I had also replied the same. The result was that, they slammed me. So go on basics.
I was asked the same question in TCS interview and I had also replied the same. The result was that, they slammed me. So go on basics.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers