'how to this error in C : incompatible type for argument 1 of 'printf'

I am new to programming in C and created a simple script as follows:


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


static float w = 10.00;


int main()
{


    printf(w);

    return 0;

}

However, when I tried to run this script the following error occurred:

error: incompatible type for argument 1 of 'printf'

This is just a simple print statement, and I have no idea why there is an error

c


Solution 1:[1]

I have not used C in a few months, but I should be able to help you out regardless. Unlike languages like Python, in C, it is important to specify what data format you are trying to print. Adding the term "%f" to your print statement will tell your compiler that you intend to print out a float value. Here is what the syntax could look like:

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

static float w = 10.00;
int main()
{
    printf("%f", w);
    return 0;
}

For more information on printing values in C, I recommend that you check out out the following resources:

As I mentioned above, I have not been programming in C recently. Thus my suggestions may not be 100% optimal. Regardless, they should help you get started on your C journey!

Solution 2:[2]

printf("w"); 

You need to add the parenthesis.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Sam Rothstein
Solution 2 Justin Frazer