<div dir="ltr"><div>So, I was trying to do this  , what I was expecting is undefined behavior by ptr[-4] and b[-4] but the undefined behavior is only shown by b[-4] . I know that a pointer can have a negative index when there is some defined value at that address . But in this case , sanitizer has to give undefined behavior for ptr[-4]  but there is no such error . I'm not sure if this is considered as Undefined Behavior or not . Or maybe some other tools exist for this type of undefined behavior .<br></div><div><br></div><div><table class="gmail-ajC" cellpadding="0"><tbody><tr class="gmail-ajv"><td colspan="2" tabindex="0" class="gmail-gG"><span class="gmail-gI"></span><br></td><td colspan="2" tabindex="0" class="gmail-gL"><div style="color:rgb(212,212,212);background-color:rgb(30,30,30);font-family:Consolas,"Liberation Mono",Courier,monospace,"Droid Sans Mono","monospace",monospace,"Droid Sans Fallback";font-weight:normal;font-size:14px;line-height:19px;white-space:pre"><div><span style="color:rgb(86,156,214)">#include</span><span style="color:rgb(212,212,212)"> </span><span style="color:rgb(86,156,214)"><</span><span style="color:rgb(206,145,120)">iostream</span><span style="color:rgb(86,156,214)">></span></div><br><div><span style="color:rgb(86,156,214)">int</span><span style="color:rgb(212,212,212)"> main</span><span style="color:rgb(220,220,220)">()</span><span style="color:rgb(212,212,212)"> </span><span style="color:rgb(220,220,220)">{</span></div><div><span style="color:rgb(212,212,212)">  </span></div><div><span style="color:rgb(212,212,212)">    </span><span style="color:rgb(86,156,214)">int</span><span style="color:rgb(212,212,212)"> b</span><span style="color:rgb(220,220,220)">[]=</span><span style="color:rgb(212,212,212)"> </span><span style="color:rgb(220,220,220)">{</span><span style="color:rgb(181,206,168)">7</span><span style="color:rgb(220,220,220)">,</span><span style="color:rgb(181,206,168)">5</span><span style="color:rgb(220,220,220)">,</span><span style="color:rgb(181,206,168)">4</span><span style="color:rgb(220,220,220)">,</span><span style="color:rgb(181,206,168)">3</span><span style="color:rgb(220,220,220)">,</span><span style="color:rgb(181,206,168)">2</span><span style="color:rgb(220,220,220)">}</span><span style="color:rgb(212,212,212)"> </span><span style="color:rgb(220,220,220)">;</span></div><br><div><span style="color:rgb(212,212,212)">    </span><span style="color:rgb(86,156,214)">char</span><span style="color:rgb(212,212,212)"> a</span><span style="color:rgb(220,220,220)">[]</span><span style="color:rgb(212,212,212)"> </span><span style="color:rgb(220,220,220)">=</span><span style="color:rgb(212,212,212)"> </span><span style="color:rgb(206,145,120)">"hello"</span><span style="color:rgb(220,220,220)">;</span></div><div><span style="color:rgb(212,212,212)">    </span><span style="color:rgb(86,156,214)">char</span><span style="color:rgb(212,212,212)"> </span><span style="color:rgb(220,220,220)">*</span><span style="color:rgb(212,212,212)">ptr </span><span style="color:rgb(220,220,220)">=</span><span style="color:rgb(212,212,212)"> a</span><span style="color:rgb(220,220,220)">;</span></div><div><span style="color:rgb(212,212,212)">    std::cout</span><span style="color:rgb(220,220,220)"><<</span><span style="color:rgb(212,212,212)"> ptr</span><span style="color:rgb(220,220,220)">[</span><span style="color:rgb(181,206,168)">0</span><span style="color:rgb(220,220,220)">]</span><span style="color:rgb(212,212,212)"> </span><span style="color:rgb(220,220,220)"><<</span><span style="color:rgb(212,212,212)"> ptr</span><span style="color:rgb(220,220,220)">[-</span><span style="color:rgb(181,206,168)">4</span><span style="color:rgb(220,220,220)">]</span><span style="color:rgb(212,212,212)"> </span><span style="color:rgb(220,220,220)"><<</span><span style="color:rgb(212,212,212)"> b</span><span style="color:rgb(220,220,220)">[</span><span style="color:rgb(181,206,168)">0</span><span style="color:rgb(220,220,220)">]</span><span style="color:rgb(212,212,212)"> </span><span style="color:rgb(220,220,220)"><<</span><span style="color:rgb(212,212,212)"> b</span><span style="color:rgb(220,220,220)">[-</span><span style="color:rgb(181,206,168)">4</span><span style="color:rgb(220,220,220)">];</span></div><div><span style="color:rgb(220,220,220)">}<br></span></div></div></td></tr></tbody></table></div></div>