![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Feb 2006
Location: India
Posts: 25
Rep Power: 0
![]() |
main() and main(int argc,char*argv[])
as we cant use function overloading in c..
then how are main() and main(int argc, char *argv[]) used? |
|
|
|
|
|
#2 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
You don't have to worry about overloading, since you only use one or another (never two or more). All you have to worry about is what the compiler does with the particular one it encounters. It does well.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#3 |
|
Programmer
Join Date: Jun 2005
Posts: 92
Rep Power: 4
![]() |
main(int argc, char *argv[]) main() |
|
|
|
|
|
#4 |
|
Programming Guru
![]() Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,260
Rep Power: 5
![]() |
The main function is a specific case in the standard, and all implementations are required to support both forms (or equivalent). This is not overloading, as Dawei said, which means that your programs are only allowed to use one of them.
|
|
|
|
|
|
#5 | |
|
Programmer
Join Date: Jun 2005
Posts: 92
Rep Power: 4
![]() |
Quote:
main(int argc, char *argv[]) to pass input to my program. Of course main(int argc, char *argv[]) is standards compliant, all it is doing is accepting arguments to a function, albeit a function that the compiler calls to begin execution of the program. |
|
|
|
|
|
|
#6 |
|
Programming Guru
![]() Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,260
Rep Power: 5
![]() |
Using int main(int argc, char *argv[]) is standard if you want your program to accept parameters at startup
In practice, on most hosted implementations such as those under Unix or windows, the input received via the arguments argc and argv typically come from a command line, but the standard does not specifically require that. In fact, the standard is silent on where the information passed in argc and argv comes from .... that is part of the implementation details of your compiler (eg the compiler specific code that sets up a few things, and then calls your main function). |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|