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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:21:14+00:00 2026-05-25T14:21:14+00:00

I want to consider to code. First it is: #include <iostream> #include <cmath> #include

  • 0

I want to consider to code. First it is:

#include <iostream>
#include <cmath>
#include <math.h>
using namespace std;
int main() {
    int s = 25;
    cout << sqrt(s) << endl;
    return 0;
}

It gave me this mistake:

>c:\users\datuashvili\documents\visual studio 2010\projects\training\training\training.cpp(9): error C2668: 'sqrt' : ambiguous call to overloaded function
1>          c:\program files\microsoft visual studio 10.0\vc\include\math.h(589): could be 'long double sqrt(long double)'
1>          c:\program files\microsoft visual studio 10.0\vc\include\math.h(541): or       'float sqrt(float)'
1>          c:\program files\microsoft visual studio 10.0\vc\include\math.h(127): or       'double sqrt(double)'
1>          while trying to match the argument list '(int)'
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

If I add type float in brackets in front of s, like this:

#include <iostream>
#include <cmath>
#include <math.h>
using namespace std;

int main() {
    int s = 25;
    cout << sqrt((float)s) << endl;
    return 0;
}

I got as I would guess, 5. And another variant is that instead of sqrt, if I write sqrtf:

#include <iostream>
#include <cmath>
#include <math.h>
using namespace std;

int main(){
    int s=25;
    cout << sqrtf((float)s) << endl;
    return 0;
}

I also got 5.

What is the difference between them? Does it means that sqrtf is same as sqrt for the float type?

  • 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-25T14:21:15+00:00Added an answer on May 25, 2026 at 2:21 pm

    Here’s a page on MSDN documentation for sqrt() and sqrtf(), that explains the difference:

    sqrt, sqrtf

    Calculates the square root.

        double sqrt(
           double x 
        );
        float sqrt(
           float x 
        );  // C++ only
        long double sqrt(
           long double x
        );  // C++ only
        float sqrtf(
           float x 
        );
    

    Parameters

    x: Nonnegative floating-point value

    Remarks

    C++ allows overloading, so users can call overloads of
    sqrt that take float or long double types. In a C program, sqrt always
    takes and returns double.

    Return Value

    The sqrt function returns the square-root of x. If x
    is negative, sqrt returns an indefinite, by default.

    So the difference in C++ is that sqrt() accepts either a double, a float or a long double while sqrtf() accepts only a float.

    As the documentation says, the only reason why there’s two different versions is because C did not support overloading, so there had to be two functions. C++ allows overloading, so there are actually three different versions of sqrt() taking floating point arguments of various sizes.

    So in C++, both your code snippets do essentially the same thing. On C, however, there would’ve been a conversion from float to double in the sqrt() call.

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

Sidebar

Related Questions

Please consider the following piece of code: int main() { typedef boost::ptr_vector<int> ptr_vector; ptr_vector
Consider the following code: while(true) { someFunction(); Thread.sleep(1000); } What I want is that,
Consider: print $foo, AAAAAAAA, $foo, BBBBBBBB; Let's say I want to use this code
Consider the following short code snippet. namespace B { public class Foo { public
I'm looking into speeding up my python code, which is all matrix math, using
Consider the following simple code: GetDlgItemText(IDC_EName,LPTSTR(cName),11); k=strlen(cName); I want to get the length of
Consider my dataTable contains 10,000 rows and i want to know the pitfall of
Consider I have an array of elements out of which I want to create
Consider the following subversion directory structure /dir1/file.txt /dir2/file.txt I want to move the file.txt
Consider this at the windows commandline. scriptA.py | scriptB.py I want to send a

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.