-
April 8th, 2009, 08:13 PM
#1
Multi-character characters?
Is there a way to make the following possible with only a character type?
char ch='10';
Thanks
-
April 8th, 2009, 08:24 PM
#2
Re: Multi-character characters?
No. You want two characters - you need space to store both. It's like asking if it's possible to fit two cars into a single parking space (at least without destroying the cars).
The typical way of storing multiple characters for a c-style string is with a char*, as in
Code:
const char* ch = "10";
-
April 8th, 2009, 08:45 PM
#3
Re: Multi-character characters?
Perhaps you mean
? Note that that's in octal; if you wanted a newline, you'd have to write '\12' (or simply '\n').
-
April 8th, 2009, 11:45 PM
#4
Re: Multi-character characters?
I know it's possible to define a four character literal, like 'abcd', which could then be held in a 32bit integer. Two characters would probably do something similar
Intel Core Duo Macbook w/ Mac OS 10.5.6
gcc 4.2.1 (i386-apple-darwin9.1.0) and Xcode 3.1.1
-
April 9th, 2009, 06:26 AM
#5
Re: Multi-character characters?
Why don't you try to experiment yourself writing something like
Code:
#include <stdio.h>
int main()
{
char t = '10'; // compiler probably will warn you, but compilation will not fail
putchar(t);
printf("\ncontent = 0x%X\n", t); // here you will see that yes, it is possible, but the value is truncated to sizeof, as expected
return 0;
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|