#include Ĭonst char *hello = 'hello, world' /* bad */Įxample 2, a string literal is used where a character constant should be used. This character constant will be converted to a pointer in an implementation-defined manner and there is little chance for the converted pointer to be valid, so this example will invoke undefined behavior. Int myArray = )Įxample 1, a character constant is used where a string literal should be used. ![]() Overstepping Array BoundariesĪrrays always starts with index 0 and ends with index array length minus 1. When -1 is converted to an unsigned int the result is the maximal possible unsigned int value, which is greater than 1000, meaning that a > b is false. This means that int operand b will get converted to unsigned int before the comparison. In this case the "common" type is unsigned int. Since 1000 is more than -1 you would expect the output to be a is more than b, however that will not be the case.Īrithmetic operations between different integral types are performed within a common type defined by the so called usual arithmetic conversions. For example, what will be output of following example? #include It is usually not a good idea to mix signed and unsigned integers in arithmetic operations. Mixing signed and unsigned integers in arithmetic operations
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |