user3132295
user3132295

Reputation: 297

difference between cast and assignment int,char in C

Can anyone please explain what the difference between explicit conversion of integer to char

int i = 100;
char c2 = (char)i;

to assignment integer type to char

char i = 100;

thank you very much

Upvotes: 2

Views: 192

Answers (1)

Oliver Charlesworth
Oliver Charlesworth

Reputation: 272457

There is no behavioural difference.

However, some compilers may be configured to warn about implicit "narrowing" conversions. So code like this may provoke a warning:

int i = ...;

char c = i;  // Implicit conversion

Upvotes: 6

Related Questions