please find the error in this program

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • saikumar123
    New Member
    • Dec 2019
    • 1

    please find the error in this program

    Code:
    #include<stdio.h>
    main ( )
    {
        int i = 1;
        int *p=&i;
        q=p;
        int *q = 5;
        printf("%d \n",*p);
    }
    Last edited by gits; Dec 10 '19, 08:31 AM. Reason: added code tags
  • dev7060
    Recognized Expert Contributor
    • Mar 2017
    • 656

    #2
    A variable cannot be used before its declaration.

    Comment

    • donbock
      Recognized Expert Top Contributor
      • Mar 2008
      • 2427

      #3
      Also, main must return int.

      Comment

      • dev7060
        Recognized Expert Contributor
        • Mar 2017
        • 656

        #4
        If the return type is not specified, it is implicitly declared as int.

        According to C99 rationale (http://port70.net/~nsz/c/c99/)
        A new feature of C99: In C89, all type specifiers could be omitted from the declaration specifiers in a declaration. In such a case int was implied. The Committee decided that the inherent danger of this feature outweighed its convenience, and so it was removed. The effect is to guarantee the production of a diagnostic that will catch an additional category of programming errors. After issuing the diagnostic, an implementation may choose to assume an implicit int and continue to translate the program in order to support existing source code that exploits this feature.
        From C99 or later, warnings are likely to be generated: "-Wimplicit-int" (https://gcc.gnu.org/onlinedocs/gcc/W...arning-Options).

        On testing the above code with TDM-GCC 4.9.2 64-bit Release, no warning was there.

        With GNU GCC, "warning: return type defaults to 'int' [-Wimplicit-int]" -> likely targeting the C99 or later version.

        Comment

        Working...