Solved

main function question

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

863 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

28 Experts available now in Live!

Get 1:1 Help Now