We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Actually, there is a problem with the code. The line char t12[2]; in the original post doesn't allocate enough space. The string "PM" requires three bytes: 'P', 'M', and a null (zero) byte to end the string. When the machine writes three bytes into a two-byte space, that final null byte is stomping over memory that doesn't belong to the t12 variable. What happens then is very hard to predict, dependent on the implementation and other factors.
The quick fix would be to correctly declare t12 as char t12[3];.
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Time Conversion
You are viewing a single comment's thread. Return to all comments →
Actually, there is a problem with the code. The line
char t12[2];
in the original post doesn't allocate enough space. The string "PM" requires three bytes: 'P', 'M', and a null (zero) byte to end the string. When the machine writes three bytes into a two-byte space, that final null byte is stomping over memory that doesn't belong to thet12
variable. What happens then is very hard to predict, dependent on the implementation and other factors.The quick fix would be to correctly declare t12 as
char t12[3];
.