Beginnner
Beginnner

Reputation: 11

Error while compiling [Warning] multi-character character constant [-Wmultichar]

I'm trying to compile the following the program but I'm facing two errors:

  1. multi-character character constant [-Wmultichar]
  2. overflow in implicit constant conversion [-Woverflow]

#include <stdio.h>
#include <conio.h>

int main()
{
    int age;
    float weight;
    char gender;

    age = 23;
    weight = 60.5;
    gender = 'M ';

    printf("Persons Profile \n\n\n Age: %i,\n\nweight: %f,\n\nGender: %c",age,weight,gender);

    getch();    
    return 0;
}

Upvotes: 0

Views: 1749

Answers (1)

user3337714
user3337714

Reputation: 673

The gender variable is of type char.
charin C represents the character type, suitable for storing a simple character—traditionally one from the ASCII encoding. More recently, UTF-8 encoded characters are common. The char type can also store small integers and is technically an integer type.

In your code gender variable contains two characters M and (space). If you remove the space it will remove both of your mentioned errors.

Change gender = 'M ';
To gender = 'M';

For further C assistance http://en.wikibooks.org/wiki/C_Programming

Upvotes: 2

Related Questions