Can the some value of array be modified?
for example:
is it be done ?Code:char a[3] = { 'a', 'b', 'c'}; now, modifying the second element, let char a[1] be equal to 'd'
Can the some value of array be modified?
for example:
is it be done ?Code:char a[3] = { 'a', 'b', 'c'}; now, modifying the second element, let char a[1] be equal to 'd'
Yes,
You could write something like
I've highlighted the bit of code that actually changes the letter. If you declared your array like:Code:#include <stdio.h> int main(void) { char a[3] = { 'a', 'b', 'c'}; int i; for (i=0; i<3; i++) printf("a[%d]: %c\n", i, a[i]); // change a[1] to the letter 'd' a[1] = 'd'; printf("\n"); for (i=0; i<3; i++) printf("a[%d]: %c\n", i, a[i]); return 0; }
Then all the characters in the array would be constant, and you wouldn't be able to change their values.Code:const char a[3] = { 'a', 'b', 'c'};
I understand! thanks
Does two-dimensional array do also like this ?
HOPE YOU UNDERSTAND.......
By associating with wise people you will become wise yourself
It's fine to celebrate success but it is more important to heed the lessons of failure
We've got to put a lot of money into changing behavior
PC specifications- 512MB RAM, Windows XP sp3, 2.79 GHz pentium D.
IDE- Microsoft Visual Studio 2008 Express Edition
I do a try , correct
thanks !
Code:char b[3][3] = {{'1','2','3'},{'4','5','6'},{'7','8','9'}}; b[0][0] = 'c'; for(int m = 0; m < 3; m++) for(int n = 0; n < 3; n++) printf("%c ",b[m][n]);