#include<stdio.h>
int main(void)
{
char a;
a="?";
}
Error i'm recieving:
warning: assignment makes integer from pointer without a cast
a="?";
#include<stdio.h>
int main(void)
{
char a;
a="?";
}
Error i'm recieving:
warning: assignment makes integer from pointer without a cast
a="?";
A char
is a one-byte integer value, used ti hold the ASCII value of a single character.
A string literal (enclosed in double quotes) is equivalent to an array of chars.
So on line 5 you are trying to assign an array (more precisely a pointer to an array) to an integer data type.
If you just want a single char then the correct syntax for the literal is to use single quotes, ie '?'
TLDR: a char and a one-character-long string are completely different animals.
While the correct form of the assignment would, as JamesCherill says, certainly be:
a = '?';
a more illustrative correction might be:
a = "?"[0];
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.