Solved

main function question

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
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 pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

758 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

19 Experts available now in Live!

Get 1:1 Help Now