how does a main() in C++ is different from main() in C?

Answer Posted / yj

First of all, make it clear that whenever we run any program the compiler search for the main() function to start execution...
Now,
The programming language C follows top down approach. Means the control moves from top to down. Hence in this we have to give main function above all the other lines of code...
But when you program in C++ which follows bottom up approach i.e., the control moves from bottom to up...For example, when we make a function in C++ we give its definition above main() and when we call that function in main(): as soon as the compiler encounter the "calling line"...the compiler now search for the definition of that function which is above the function main(). Now u visualise that the control is moving from bottom to up.

Hence,
"The function main() in C has to be given at the top. But in C++the function main can be at the bottom also"

Is This Answer Correct ?    25 Yes 13 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are the three main types of variables?

699


What is class and object with example?

674


There are two base class B1,B2 and there is one class D which is derived from both classes, Explain the flow of calling constructors and destructors when an object of derived class is instantiated.

1558


officer say me - i am offered to a smoking , then what can you say

1683


what are the different types of qualifier in java?

1919






What are properties in oop?

693


what's the basic's in dot net

1812


What is destructor example?

685


What is destructor oops?

710


What is encapsulation and abstraction? How are they implemented in C++?

719


What is Difference Between Inheritance and creating object and getting data? means Class A extends B{ B.getMethod();} (OR) Class A{ b obj=new B(); obj.getMethod(); }

2077


Get me an image implementation program.

1633


What does I oop mean?

709


What is constructor overloading in oop?

710


Write a program to reverse a string using recursive function?

1879