hi, wat datatype to use if i want to store both integers & char in an array? can i use String...and how to use String?
datatype to store both char n int in an array
Collapse
X
-
Tags: None
-
Originally posted by luking4anshi, wat datatype to use if i want to store both integers & char in an array? can i use String...and how to use String?
raghuram -
Comment
-
A char and an int are both integers. The char is 8 bytes and the int is at least 16 but may be more.
There are no character variables.
That means an int with 65 can be displayed as A just as well as a char with 65. It's just that functions with char arguments assume you want to see the A whereas functions with int arguments assume you want to see 65.
The syntax 'A' is an integer syntax. It tells the compiler to look up the value corresponding to A in the ASCII table and to use that value. In this case, 65.Comment
-
Thanks
Thanks... It worked for me ... i created a structure and its array as u told...
struct maze{int x;char y;};
void main ()
{maze a[10][10];
//to store in int part
cin>>a[0][0].x;
//to store in char part
cin>>a[0][0].y;
//to access int part
cout<<a[0][0].x;
//to access char part
cout<<a[0][0].y;
}Comment
Comment