Solved

main function question

Posted on 2000-04-27
3
214 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 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
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 viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

733 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