?
Solved

main function question

Posted on 2000-04-27
3
Medium Priority
?
224 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 22

Accepted Solution

by:
nietod earned 120 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

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…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
Suggested Courses
Course of the Month13 days, 21 hours left to enroll

801 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