A
aarklon
Hi all,
what exactly is the purpose of multi-character constant..???
what exactly is the purpose of multi-character constant..???
Hi all,
what exactly is the purpose of multi-character constant..???
Tor said:Do you mean UCN?
what exactly is the purpose of multi-character constant..???
[email protected] said:what exactly is the purpose of multi-character constant..???
It's not 100% clear what you mean; an example would be helpful.
If you mean something like 'ab', the best answer is that if you have to
ask, you don't need to know. All the standard says is (C99 6.4.4.4p10):
The value of an integer character constant containing more than
one character (e.g., 'ab') [...] is implementation-defined.
[email protected] said:what exactly is the purpose of multi-character constant..???
It's not 100% clear what you mean; an example would be helpful.
If you mean something like 'ab', the best answer is that if you have
to
ask, you don't need to know. All the standard says is (C99
6.4.4.4p10):
The value of an integer character constant containing more than
one character (e.g., 'ab') [...] is implementation-defined.
In practice, the value of 'ab' is likely to be either 'a' * 256 + 'b'
or 'b' * 256 + 'a'. It will vary from one compiler to another.
I don't think that the above argument of yours is correct.
i have seen a program like this:-
#include<stdio.h>
int main(void)
{
char str['11'] = {"work hard"};
printf("%d\n",sizeof(str));
return(EXIT_SUCCESS);
}
and the o/p is given as 12593
now by your reasoning the o/p should be 1*16 +1 = 17 isn't it...???
10:45 am:
(e-mail address removed) wrote:
what exactly is the purpose of multi-character constant..???
It's not 100% clear what you mean; an example would be helpful.
If you mean something like 'ab', the best answer is that if you have
to
ask, you don't need to know. All the standard says is (C99
6.4.4.4p10):
The value of an integer character constant containing more than
one character (e.g., 'ab') [...] is implementation-defined.In practice, the value of 'ab' is likely to be either 'a' * 256 + 'b'
or 'b' * 256 + 'a'. It will vary from one compiler to another.I don't think that the above argument of yours is correct.i have seen a program like this:-#include<stdio.h>
int main(void)
{
char str['11'] = {"work hard"};
printf("%d\n",sizeof(str));
return(EXIT_SUCCESS);
}and the o/p is given as 12593
now by your reasoning the o/p should be 1*16 +1 = 17 isn't it...???
No. By his reasoning it would be:
'1' * 256 + '1'
or
'1' * 256 + '1'
Note the single quotes around 1. The compiler replaces the character
literal with whatever encoding the implementation uses for it. Thus
if '1' is represented by the value 50 (just an example) the expression
would be:
50 * 256 + 50
or
50 * 256 + 50
As Keith said this is implementation dependent behaviour and the
Standard has very little to say about how multi-character character
constants are interpreted.
Apply the above formula and see that Keith conclusion was correct for
ASCII based systems. In the ASCII encoding '1' is represented by the
number 49. Thus:
49 * 256 + 49 = 12593
But you cannot depend on this in general.
okay you are correct i got the point. but i made a mistake in earlier
post it should have been '1' *256 + '1'
BTW on what basis we are selecting this value of 256...???
>
okay you are correct i got the point. but i made a mistake in earlier
post it should have been '1' *256 + '1'
BTW on what basis we are selecting this value of 256...???
Hi all,
what exactly is the purpose of multi-character constant..???
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.