some basic question about C

This is a discussion on some basic question about C within the C Programming forums, part of the General Programming Boards category; what is the difference between the two: Code: int main (void) { return 0; } and int main () { ...

  1. #1
    Registered User
    Join Date
    Feb 2010
    Posts
    32

    some basic question about C

    what is the difference between the two:
    Code:
    int main (void)
    {
    return 0;
    }
    
    and
    
    int main ()
    {
    return 0;
    }
    and can someone explain what does a destructive and non-destructive function mean?
    thx very much

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    One specifies that there are no parameters, and the other specifies an unknown number of parameters.

    Destructive is bad. Non-destructive is not destructive.


    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,832
    I've never heard of the term but a quick search turned up this:

    Failure of Implicit Conventions: Determining Function Destructiveness

    " destructive functions cause some change outside of the lexical scope of their function, whereas non-destructive functions do not cause changes outside of their lexical scope."
    Last edited by nonoob; 03-08-2010 at 07:44 PM.

  4. #4
    Registered User
    Join Date
    Feb 2010
    Posts
    26
    void specifies no arguments.


    Code:
    #include<stdio.h>
    #include<stdlib.h>
            static int i=1;
    int main()
    {
            printf("function");
            if(i++==5)
                  exit(0);
            main(2);
    }
    In the above code I didn't use void in the main function.
    I called the main function with the argument 2.So the message "function" will get printed for five times.

    If I changed the code like the following,

    Code:
    #include<stdio.h>
    #include<stdlib.h>
    static int i=1;
    int main(void)
    {
            printf("hai");
            if(i++==5)
                  exit(0);
            main(2);
    }
    I have used the void as a argument type.So main function wont accept any argument.So it will throw an error.

  5. #5
    Registered User
    Join Date
    Mar 2010
    Posts
    1

    Help! Please.

    Just started to learn C programming. Does anyone know why I get a error with this code. The program runs fine in the console but in Xcode it gives me an error saying "Return type defaults to "int"" next to the main (int argc, const char* argv[]) { part of the code. Thank you for your help!

    #include <stdio.h>

    main (int argc, const char* argv[]) {

    int i;

    i = 20;


    printf("Number %d is Peter's favorite number\n", i);


    return 0;

    }

  6. #6
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    You didn't specify a return type for main.


    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A basic math programming question
    By hebali in forum C Programming
    Replies: 38
    Last Post: 02-25-2008, 03:18 PM
  2. Basic question about GSL ODE func RK4
    By cosmich in forum Game Programming
    Replies: 1
    Last Post: 05-07-2007, 02:27 AM
  3. Basic question about RK4
    By cosmich in forum C++ Programming
    Replies: 0
    Last Post: 05-07-2007, 02:24 AM
  4. A very basic question
    By AshFooYoung in forum C Programming
    Replies: 8
    Last Post: 10-07-2001, 03:37 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21