C language: i dont understand why it works -


does knows happens when char returned when int expected?

char testunc1(char a) {     return a; }  void main() {      int x1;     x1 = testfunc1(7);     printf("%d\n",x1); } 

the char implicitly converted int.

in section 6.5.16.1 paragraph 2 of c99 standard:

in simple assignment (=), value of right operand converted type of assignment expression , replaces value stored in object designated left operand.

the type of assignment expression defined in section 6.5.16 paragraph 3:

the type of assignment expression type of left operand unless left operand has qualified type, in case unqualified version of type of left operand.

since variable of type int, returned char value converted type int specified in section 6.5.16.1 of c99 standard.

in case, value 7 can represented int, no loss of precision occurs 7 stored in int variable.


Comments