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 3789446
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T12:09:29+00:00 2026-05-19T12:09:29+00:00

Hopefully this is a very simple question. Following is the C pgm (test.c) I

  • 0

Hopefully this is a very simple question. Following is the C pgm (test.c) I have.

#include <stdio.h>
//#include <stdlib.h>

int main (int argc, char *argv[]) {
    int intValue = atoi("1");
    double doubleValue = atof("2");
    fprintf(stdout,"The intValue is %d and the doubleValue is %g\n", intValue, doubleValue);
    return 0;
}

Note that I am using atoi() and atof() from stdlib.h, but I do not include that header file. I compile the pgm (gcc test.c) and get no compiler error!

I run the pgm (./a.out) and here is the output, which is wrong.

The intValue is 1 and the doubleValue is 0

Now I include stdlib.h (by removing the comments before the #include) and recompile it and run it again. This time I get the right output:

The intValue is 1 and the doubleValue is 2

How come the compiler did not complain about not including the stdlib.h and still let me use the atoi(), atof() functions?

My gcc info:

$ gcc --version
gcc (GCC) 4.1.2 20070925 (Red Hat 4.1.2-27)

Any thoughts appreciated!

  • 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-19T12:09:30+00:00Added an answer on May 19, 2026 at 12:09 pm

    For historical reasons — specifically, compatibility with very old C programs (pre-C89) — using a function without having declared it first only provokes a warning from GCC, not an error. But the return type of such a function is assumed to be int, not double, which is why the program executes incorrectly.

    If you use -Wall on the command line, you get a diagnostic:

    $ gcc -Wall test.c
    test.c: In function ‘main’:
    test.c:5: warning: implicit declaration of function ‘atoi’
    test.c:6: warning: implicit declaration of function ‘atof’
    

    You should use -Wall basically always. Other very useful warning options for new code are -Wextra, -Wstrict-prototypes, -Wmissing-prototypes, -pedantic, and -Wwrite-strings, but compared to -Wall they have much higher false positive rates.

    Tangentially: never use atoi nor atof, they hide input errors. Use strtol and strtod instead.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is hopefully a very simple maths question. If I have two number ranges,
Hopefully this is a very simple question. I have a makefile pattern rule that
This is a very simple, (hopefully) question. I am new to working with DateTime
This isn't a very simple question, but hopefully someone has run across it. I
This is hopefully a very simple question, but one a lot of Googling has
I don't understand MEF very well, so hopefully this is a simple fix of
Hopefully this is simple: I have a relatively long list where each list item
Hopefully this question isn't as subjective as I think it may be. I have
This is probably a very simple question, but I can't find the answer, so
Very simple question, hopefully. So, in Python you can split up strings using indices

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.