i have declared
char arr[10][10];
and did this:
for(i=1;i<=n;i++){
arr[i] = (char)i;
}
but it wouldn't work..
i want to put the number inside the array.. y does this error?
i have declared
char arr[10][10];
and did this:
for(i=1;i<=n;i++){
arr[i] = (char)i;
}
but it wouldn't work..
i want to put the number inside the array.. y does this error?
You have a two dimensional array, so you need to dereference it twice.
arr[i] = (char)i; // wrong. arr[i] is an address, not a char.
arr[i][0] = (char)i; // right. now it's a char.
VernonDozier is correct
If we go though the structure of array
It lock some thing like this
int num[2][3];
-----------------------------------
| num[0][0] | num[0][1] | num[0][2] | <- row 0
-----------------------------------
| num[1][0] | num[1][1] | num[1][2] | <- row 1
-----------------------------------
column 0 column 1 column 2
num[0][0] -> Representing the 1st row 1st column
num[0][1] -> Representing the 1st row 2nd column
num[0][2] -> Representing the 1st row 3rd column
num[0][0] -> Representing the 2nd row 1st column
num[0][1] -> Representing the 2nd row 2nd column
num[0][2] -> Representing the 2nd row 3rd column
and you try to access array index like this
num[i]=(char)i; //arr[i]=(char)i; in your code
which is not representing any particular memory location to store data
Best Of Luck
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.