By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,617 Members | 1,600 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,617 IT Pros & Developers. It's quick & easy.

Whats the meaning of this code

P: n/a
sam
HI,
Whats the meaning of this code:-

char buff[100];
memset(buff, 'A' , 100);
sometimes we can place hex value in
place of 'A' like 0x90c
but how this code function actually.

thanks in advance

Apr 23 '07 #1
Share this Question
Share on Google+
5 Replies


P: n/a
sam wrote:
HI,
Whats the meaning of this code:-

char buff[100];
memset(buff, 'A' , 100);
sometimes we can place hex value in
place of 'A' like 0x90c
I doubt that 0x90c can replace 'A' generally. The value 0x90c
is larger than the value a 'char' object can contain (usually).
but how this code function actually.
The declaration/definion of 'buff' functions by declaring and
defining that array. It's left uninitialised. How exactly it
is allocated is unspecified. Elements of 'buff' have automatic
storage duration, most likely (since those two lines of code
are undoubtedly part of a function body).

'memset' is a function, so the second statement calls the
function and passes it three arguments. The description of
'memset' says that it fills the memory pointed to by the first
argument with the value of the second argument, counting the
bytes using the third argument. IOW, the entire array 'buff'
gets filled with characters 'A', all 100 elemenst of 'buff'
will have the value 'A' after 'memset' returns.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Apr 23 '07 #2

P: n/a
On Apr 23, 9:05 am, sam <sameer...@gmail.comwrote:
HI,
Whats the meaning of this code:-

char buff[100];
memset(buff, 'A' , 100);
sometimes we can place hex value in
place of 'A' like 0x90c
but how this code function actually.

thanks in advance
This is just setting a memory area (buff) with
initial values.

Apr 23 '07 #3

P: n/a
An**********@gmail.com wrote:
On Apr 23, 9:05 am, sam <sameer...@gmail.comwrote:
>HI,
Whats the meaning of this code:-

char buff[100];
memset(buff, 'A' , 100);
sometimes we can place hex value in
place of 'A' like 0x90c
but how this code function actually.

thanks in advance
This is just setting a memory area (buff) with
initial values.
I would omit the word "initial" from this explanation.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Apr 23 '07 #4

P: n/a
sam
On Apr 23, 6:05 pm, sam <sameer...@gmail.comwrote:
HI,
Whats the meaning of this code:-

char buff[100];
memset(buff, 'A' , 100);
sometimes we can place hex value in
place of 'A' like 0x90c
but how this code function actually.

thanks in advance
I am not saying 'A' is replaced by
0x90c but i am saying we can
place any hex value as per
requirement in place of 'A'
and I want brief explanation.

Apr 23 '07 #5

P: n/a
sam wrote:
On Apr 23, 6:05 pm, sam <sameer...@gmail.comwrote:
>HI,
Whats the meaning of this code:-

char buff[100];
memset(buff, 'A' , 100);
sometimes we can place hex value in
place of 'A' like 0x90c
but how this code function actually.

thanks in advance

I am not saying 'A' is replaced by
0x90c but i am saying we can
place any hex value as per
requirement in place of 'A'
and I want brief explanation.
An explanation would probably be that 'char' is a type that
can store values (of a certain range). 'A' represents a value
that can be stored in a 'char' object. So does 0 and any
other integral that can be converted to 'char'. The hex
notation is just a way of representing the value. For example,
in ASCII, 0x41 is the hex equivalent of 'A' (the capital form
of the first letter of the Latin alphabet). 65 is the decimal
equivalent of 0x41 (and of 'A'). 0101 is the octal equivalent.

RTFM on memset. Then build a minimal program with your code
and run it under a debugger, looking at the elements of the
array 'buff' as you step through your code.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Apr 23 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.