Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Whats the meaning of this code

Reply
Thread Tools

Whats the meaning of this code

 
 
sam
Guest
Posts: n/a
 
      04-23-2007
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

 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      04-23-2007
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


 
Reply With Quote
 
 
 
 
AnonMail2005@gmail.com
Guest
Posts: n/a
 
      04-23-2007
On Apr 23, 9:05 am, sam <(E-Mail Removed)> 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
> but how this code function actually.
>
> thanks in advance

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

 
Reply With Quote
 
Victor Bazarov
Guest
Posts: n/a
 
      04-23-2007
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> On Apr 23, 9:05 am, sam <(E-Mail Removed)> 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
>> 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


 
Reply With Quote
 
sam
Guest
Posts: n/a
 
      04-23-2007
On Apr 23, 6:05 pm, sam <(E-Mail Removed)> 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
> 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.

 
Reply With Quote
 
Victor Bazarov
Guest
Posts: n/a
 
      04-23-2007
sam wrote:
> On Apr 23, 6:05 pm, sam <(E-Mail Removed)> 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
>> 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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Understanding search queries, semantics, and "Meaning" ...aren't weall looking for meaning? 5lvqbwl02@sneakemail.com Python 4 01-14-2009 02:28 PM
Whats the meaning of this code sam C++ 3 01-30-2007 06:53 PM
Re: Whats the meaning of this code Noah Roberts C Programming 5 01-24-2007 06:10 PM
Whats the meaning of this code sam C++ 3 01-24-2007 05:34 PM
Olympus C740UZ - NIMH AA Specs - Whats the meaning ? dave Digital Photography 18 11-23-2004 07:44 PM



Advertisments