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

Answers were Sorted based on User's Feedback



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

Answer / seetha

hello kunal... ur answer was simply wrong..
becoz in both c and c++ also if v use like int main() and
the absence of return 0;
will give only warning message to us... i just complied and
telling this...
if u want to check me... you just compile in both the
language and tell......
without knowing answers pls dont update urself....

Is This Answer Correct ?    29 Yes 12 No

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

Answer / 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

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

Answer / vishal palan

In C the main() does not return any value by default. But in C++ the main() returns value int by default.
Again
In U can complie progm by writing main(){....}
But in C++ u have to return int main() {...return 0;}
or void main() {...}

Is This Answer Correct ?    16 Yes 13 No

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

Answer / shivam

in c++ this approach is based on the concept of clint server model . the class definition including the member functions cositute the server that provides services to the main() main function program in c the program starts from main()

Is This Answer Correct ?    0 Yes 0 No

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

Answer / jit

In C if we write a program like
int main()
{
static int i = 5;
if (--i){
printf("%d ", i);
main(10);
}
}

It works but not in C++

Is This Answer Correct ?    0 Yes 1 No

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

Answer / hamza

in C++, you do not need to type "return 0;" statement in a [ int main() {} ]as it will be provided automatically but not in case of C.

Is This Answer Correct ?    22 Yes 32 No

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

Answer / bhanu

in c main() is a function, in c++ main() a class

Is This Answer Correct ?    8 Yes 24 No

Post New Answer

More OOPS Interview Questions

define a string class. overload the operator == to compare two strings

2 Answers   Birla, Ericsson, HCL, Infosys, Infotech, MCAS, Satyam,


How do you answer polymorphism?

0 Answers  


What is the real time example of encapsulation?

0 Answers  


How many types of access specifier in c# and vb.net?

1 Answers   Infosys,


What is public, protected, private?

6 Answers   IBS, Satyam,






what is difference b/w object based and object oriented programming language?

18 Answers   Chaitanya, College School Exams Tests, Educomp, IBM, Infosys, Telko,


Why do pointers exist?

0 Answers  


Why is polymorphism used?

0 Answers  


Hi friends I have experience of 6 months in website design and maintanence. Now i am looking for other IT jobs.. to switch platform. please post any interview you know in chennai.

0 Answers  


i had specified the access specifier for abstarct class member like (pure virtual function) as private.But it can be accessed by the derived class.How the private member of one class is accessed by other class.if any body face this problem and found the solution plz reply to me.

1 Answers   Syntel,


What is abstraction?

9 Answers  


for example A,B,C,D are class all the 4 class contain one method who() but the method who() implementaion is differnet among each class. the relation among the 4 class are A is base class and is inherited by B and C.and from this two B and C where D is inherited. the question is i want to display the output who() method in all the classes(A,B,C,D)the output of who() method is diferrent amond all the class(A,B,C,D) ------A------ virtuval who(print a) override | | who(print b) B C override who(print c) | | -------D------ override who(print d)

2 Answers  


Categories