Program does not compile with miscellaneous errors

Asked

Viewed 144 times

3

What’s wrong here? I can’t see the error.

#include <stdio.h>

void Main(void)
{
    int a = 9;
    int b = 3;
    int c = 0;

    int *p = &b;
    c = a/*p;

    printf("%d \n", c);


}
  • 2

    At these times it always helps to show which error message is returned by the compiler.

  • truth @hugomg

  • 4

    @drd0sPy So you don’t want [Edit] the question to include the error message as hugomg suggested?

1 answer

8


There are three mistakes:

  • The main function should call main and not Main.
  • This function must return a int and not void. Some compilers accept this form but this does not mean it is correct to use in standard C.
  • the use of /* is a start of comment. You need to ensure that there is no ambiguity using parentheses.

Correct code:

#include <stdio.h>

int main(void) {
    int a = 9;
    int b = 3;
    int *p = &b;
    int c = a / (*p);
    printf("%d \n", c);
}

Behold working in the ideone. And in the repl it.. Also put on the Github for future reference.

  • Thanks @bigown

  • Doesn’t Have To Be int main In Visual C++ 2013 Roda De Boa Como void.

  • 2

    @axell13 I edited to clarify this point

  • Instead of parentheses to avoid ambiguity, you can also use white space (white space is cheap and makes code more readable): c = a / *p;

Browser other questions tagged

You are not signed in. Login or sign up in order to post.