Блог пользователя ethico

Автор ethico, история, 5 лет назад, По-английски

Hey fellows,

-->i want to know about memset,how its work,because when i put 0 or -1 as like as memset(a,-1,a.sizeof(a)) or memset(a,0,a.sizeof(a)),i am getting values,but if i put any other random number,why it is showing garbage values?

--> moreover,can u guys suggest me online best website for learning **cpp(c++).

  • Проголосовать: нравится
  • -9
  • Проголосовать: не нравится

»
5 лет назад, # |
Rev. 3   Проголосовать: нравится 0 Проголосовать: не нравится

That is because memset sets values byte by byte. This will not be a problem for 0 or -1, because all the bit values are equal in 0 or -1. However, if you choose any other integer like 5, for example, we will get the following result:

00000101 00000101 00000101 00000101 (84215045)

Memset will set each of the 4 bytes of the integer to 5, and this will result in a completely different integer value.

Although, you could have just googled this.

»
5 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Look at this link :- Link