Exforsys
+ Reply to Thread
Results 1 to 6 of 6

What is the differnce between.....

This is a discussion on What is the differnce between..... within the C and C++ forums, part of the Programming Talk category; What's the difference between main() / void main() / int main() / int main(void) / int main(int argc, char *argv[])...

  1. #1
    Adrian is offline Senior Member Array
    Join Date
    Apr 2006
    Answers
    124

    What is the differnce between.....

    What's the difference between main() / void main() / int main() / int main(void) / int main(int argc, char *argv[])


  2. #2
    techguru is offline Senior Member Array
    Join Date
    Mar 2005
    Answers
    112
    Quote Originally Posted by Adrian View Post
    What's the difference between main() / void main() / int main() / int main(void) / int main(int argc, char *argv[])

    int main ( void )
    int main ( int argc, char *argv[] )
    Slight variations of the above are acceptable, where int can be replaced by a typedef name defined as int, or the type of argv can be written as char ** argv, and so on.
    The first option is used when you do not require access to the command line arguments.
    The names argc and argv are identifiers that can be changed if you so desire, but sticking to argc/argv is convention. The return type of main() must always be an int, this allows a return code to be passed to the invoker.

    for more ... Cprogramming.com: FAQ


  3. #3
    viswanathrajuvk is offline Junior Member Array
    Join Date
    Oct 2005
    Answers
    1
    I think, According to me
    int main()
    and
    int main(void) has no difference. Both are same.


  4. #4
    techguru is offline Senior Member Array
    Join Date
    Mar 2005
    Answers
    112
    I was reading at news groups... seems to be it's not clear,....


    The first option is used when you do not require access to the command line arguments.

    The return type of main() must always be an int, this allows a return code to be passed to the invoker.


  5. #5
    rash_i43 is offline Junior Member Array
    Join Date
    Nov 2006
    Answers
    1
    void main() means returning the main() with void datatype.
    int main() means returning the main() with int datatype.
    int main(void) means returning the main() with int datatype and no argumernts.


  6. #6
    usha ranawade is offline Junior Member Array
    Join Date
    Nov 2006
    Answers
    2

    answer by usha

    when you write
    1) main(), means it is a main() function using standard C syntax.
    2) void main() means you are using ANSI C/C++ syntax.This function is not returning any data type i.e. nothing
    3)int main() means you are using ANSI C/C++ syntax.This function is returning integer data type
    4) int main(void) means you are using ANSI C/C++ syntax.This function is returning int data type and you are not passing any actual parameter.
    5) int main(int argc, char *argv[]) means you are using ANSI C/C++ syntax.This function is returning int data type and you are passing parameters as a command line argument first parameter i.e.argc will store number of arguments whose data type is integer and second parameter will store actual arguments their data types are pointer to characters.


    •    Sponsored Ads



Latest Article

Network Security Risk Assessment and Measurement

Read More...