Whats the meaning of this code

S

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
 
V

Victor Bazarov

sam said:
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
 
A

AnonMail2005

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.
 
V

Victor Bazarov

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
 
S

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

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.
 
V

Victor Bazarov

sam said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top