Solved

main function question

Posted on 2000-04-27
3
200 Views
Last Modified: 2010-04-02
in this code would the main function be void?

#include <iostream.h>
#include <fstream.h>

int num[2][7] = {0,0};

int hold[2][7];

for (int x =0; x < 2; ++x)
{
     for (int y = 0; y < 5; ++y)
     {
         cout << "Please enter number for position (" << x << "," << y << "): ";
         cin  >> hold [x][y];
     }
}





0
Comment
Question by:nationnon
  • 2
3 Comments
 
LVL 22

Accepted Solution

by:
nietod earned 30 total points
ID: 2754782
I don't know what you mean by

"would the main function be void? "

but I can say that in standard C++ all programs must have a main() function.  that is the function where execution of the program begins.  This program does not have a main() so it is incompete.  It will not compile and link successfully so you will not be able to run it.  

(Note it could be compiled and linked to another file that does have a main, then the resulting program could be run.)

Let me know if you have any questions.
0
 
LVL 2

Expert Comment

by:abesoft
ID: 2755418
According to the ARM, main must always return an int.  Some compilers (like Microsoft's) allow main to be a void function, but I really don't know why they do that.

Under DOS and UNIX (at least for the compilers I've used) the value returned from main is the "error code" or "result" that the application returns to the caller.  A void main usually turns into a result of 0.
0
 
LVL 22

Expert Comment

by:nietod
ID: 2755490
The ARM is long long out of date, you should use the C++ standard instead.

The standard does state that main() must return an int (like the ARM).   But I don't think that is what he is asking about.
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now