#include<stdio.h>
 int main(void)
 {
 char a; 
 a="?";
 }

Error i'm recieving:
warning: assignment makes integer from pointer without a cast
a="?";

Recommended Answers

All 2 Replies

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.

commented: I've heard that programmers consume coffee and emit code are animals too. Each one very different from the next. +15

While the correct form of the assignment would, as JamesCherill says, certainly be:

a = '?';

a more illustrative correction might be:

a = "?"[0];
commented: Nice! +15
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.