Robby
2009-09-10 01:14:01 UTC
Hello,
I nevery really use memset() in my code , I usually innitialize all my array
values through a for-loop. But for curiosity purpose, why does memset work
only with char arrays?
For example, the following works:
=========================
int main()
{
int i;
char t;
char buf[100];
memset(buf, 'X', 100);
for(i=0; i<100; i++)
t = buf[i]; // t retrieves the right innitialized values from buf!
return 0;
}
===================================
But this doesn't ???
==================================
int main()
{
int i;
int t;
int h[100];
memset(h,11,100);
for(i=0; i<100; i++)
t = h[i]; // t does not retrieve the right innitialized values from h !
return 0;
}
==================================
The actual definition of memset is:
"The most common use of memset() is to initialize a region of memory to some
value."
So isn't an array of integers a valid region of memory that can be set by
memset?
Just asking!
PS Thankyou for all replies!
I nevery really use memset() in my code , I usually innitialize all my array
values through a for-loop. But for curiosity purpose, why does memset work
only with char arrays?
For example, the following works:
=========================
int main()
{
int i;
char t;
char buf[100];
memset(buf, 'X', 100);
for(i=0; i<100; i++)
t = buf[i]; // t retrieves the right innitialized values from buf!
return 0;
}
===================================
But this doesn't ???
==================================
int main()
{
int i;
int t;
int h[100];
memset(h,11,100);
for(i=0; i<100; i++)
t = h[i]; // t does not retrieve the right innitialized values from h !
return 0;
}
==================================
The actual definition of memset is:
"The most common use of memset() is to initialize a region of memory to some
value."
So isn't an array of integers a valid region of memory that can be set by
memset?
Just asking!
PS Thankyou for all replies!
--
Best regards
Roberto
Best regards
Roberto