Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6943635
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:10:54+00:00 2026-05-27T13:10:54+00:00

#include <stdio.h> void main() { extern int fun(float); int a=fun(3.5); printf(%d,a); } int fun(aa)

  • 0
#include <stdio.h>
void main() {
    extern int fun(float);
    int a=fun(3.5);
    printf("%d",a);
}

int fun(aa)
float aa;
{
    return ((int)aa);
}

The code block mentioned above compiles fine on my Visual Studio 8 compiler though output is a junk value. But when I compiled the same code on gcc-4.3.4, I got the following compilation error:

prog.c:2: warning: return type of ‘main’ is not ‘int’
prog.c:8: error: conflicting types for ‘fun’
prog.c:3: error: previous declaration of ‘fun’ was here

How will it work when it has following properties:

  1. There is a variable declaration before the beginning of function body.
  2. The function definition does not have the parameter type of the variable.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T13:10:55+00:00Added an answer on May 27, 2026 at 1:10 pm

    The function is written in K&R style, and your prototype for it is incorrect. In fact, there are other problems too…

    #include <stdio.h>
    void main() {
        extern int fun(float);
        int a=fun(3.5);
        printf("%d",a);
    }
    
    int fun(aa)
    float aa;
    {
        return ((int)aa);
    }
    

    The return type of main() is int, at least in Standard C. Your print statement should include a newline.

    Your prototype would be OK if the function fun() were written with a prototype:

    int fun(float aa) { ... }
    

    However, the function is written in K&R style, and therefore the function expects to be passed a double which it will convert to float:

    int fun(double aa_arg) { float aa = aa_arg; ... }
    

    In K&R C, all float values were passed as double. This is why you are getting garbage; you are lying (probably unwittingly) to your compiler, and it is getting its own back by doing GIGO on you.

    FWIW: GCC 4.6.1 refuses to compile your code (even without any warning settings). It complains:

    f1.c: In function ‘main’:
    f1.c:2: warning: return type of ‘main’ is not ‘int’
    f1.c: At top level:
    f1.c:9: error: conflicting types for ‘fun’
    f1.c:3: error: previous declaration of ‘fun’ was here
    

    You can fix this in a number of different ways:

    #include <stdio.h>
    int main(void)
    {
        extern int fun(float);
        int a = fun(3.5);
        printf("%d\n", a);
        return(0);
    }
    
    int fun(float aa)
    {
        return ((int)aa);
    }
    

    Or:

    #include <stdio.h>
    int main(void)
    {
        extern int fun(double);
        int a = fun(3.5);
        printf("%d\n", a);
        return(0);
    }
    
    int fun(double aa)
    {
        return ((int)aa);
    }
    

    Or:

    #include <stdio.h>
    int main(void)
    {
        extern int fun(double);
        int a = fun(3.5);
        printf("%d\n", a);
        return(0);
    }
    
    int fun(aa)
    double aa;
    {
        return ((int)aa);
    }
    

    Or:

    #include <stdio.h>
    int main(void)
    {
        extern int fun(double);
        int a = fun(3.5);
        printf("%d\n", a);
        return(0);
    }
    
    int fun(aa)
    float aa;
    {
        return ((int)aa);
    }
    

    Or:

    #include <stdio.h>
    int main(void)
    {
        extern int fun();
        int a = fun(3.5);
        printf("%d\n", a);
        return(0);
    }
    
    int fun(aa)
    float aa;
    {
        return ((int)aa);
    }
    

    I believe these are all correct and they all should compile without warnings (unless you ask the compiler to complain about old style (K&R) function definitions, etc).

    With GCC set to rather fussy, I get the warnings:

    /usr/bin/gcc -g -std=c99 -Wall -Wextra -Wmissing-prototypes -Wstrict-prototypes -Wold-style-definition f2.c -o f2  
    f2.c:12: warning: no previous prototype for ‘fun’
    /usr/bin/gcc -g -std=c99 -Wall -Wextra -Wmissing-prototypes -Wstrict-prototypes -Wold-style-definition f3.c -o f3  
    f3.c:12: warning: no previous prototype for ‘fun’
    /usr/bin/gcc -g -std=c99 -Wall -Wextra -Wmissing-prototypes -Wstrict-prototypes -Wold-style-definition f4.c -o f4  
    f4.c:12: warning: function declaration isn’t a prototype
    f4.c: In function ‘fun’:
    f4.c:13: warning: old-style function definition
    /usr/bin/gcc -g -std=c99 -Wall -Wextra -Wmissing-prototypes -Wstrict-prototypes -Wold-style-definition f5.c -o f5  
    f5.c:12: warning: function declaration isn’t a prototype
    f5.c: In function ‘fun’:
    f5.c:13: warning: old-style function definition
    /usr/bin/gcc -g -std=c99 -Wall -Wextra -Wmissing-prototypes -Wstrict-prototypes -Wold-style-definition f6.c -o f6  
    f6.c: In function ‘main’:
    f6.c:5: warning: function declaration isn’t a prototype
    f6.c: At top level:
    f6.c:12: warning: function declaration isn’t a prototype
    f6.c: In function ‘fun’:
    f6.c:13: warning: old-style function definition
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have the following code: #include <stdio.h> int main(void) { float a[4] __attribute__((aligned(0x1000))) =
#include<stdio.h> void function(int); int main() { int x; printf(Enter x:); scanf(%d, &x); function(x); return
consider the code #include<stdio.h> int main(void) { char* a; scanf(%s,a);//&a and &a[0] give same
Here is my code: #include <stdio.h> int main(void) { FILE *fp; unsigned int i;
I got this C code. #include <stdio.h> int main(void) { int n, d, i;
#include<stdio.h> void foo(int **arr) { arr[1][1]++; } main() { int arr[20][20]; printf(%d\n,arr[1][1]); foo((int**)arr); printf(%d\n,arr[1][1]);
Consider the code: #include <stdio.h> int x; int main (void) { } The value
Consider this C code: #include stdio.h int main(void) { int count = 5; unsigned
#include <string.h> #include <stdlib.h> #include <stdio.h> int main(void) { unsigned char *stole; unsigned char
#include<stdio.h> #include<signal.h> #include<stdlib.h> void handler(int signo) { printf(First statement); system(date); exit(EXIT_SUCCESS); } int main()

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.