Code reposted:
Code:
#include<stdio.h>
main()
{
/* int c_A,c_a,c_return; */
char c_A, c_a, c_return; /* characters - each 1 byte */
int i;
char c[10]; /* character array - each element has 1 byte*/
/* or can we call it a string? */
c_A='A';
c_a='a';
c_return='\n';
c[0]='0'; c[1]='1'; c[2]='2';
c[3]='3'; c[4]='4'; c[5]='5';
c[6]='6'; c[7]='7'; c[8]='8';
c[9]='9';
for(i=0; i<10; i++) /* first c[i] is promoted to int */
printf("int: %d char: %c \n", c[i], c[i]);
printf("c= %s \n", c); /* also print c as a string */
printf("\n \n");
printf("c_A= %d \n", c_A); /* char promoted to int */
printf("c_a= %d \n", c_a);
printf("c_return= %d \n", c_return);
printf("\n");
printf("c_A repr: %c \n", c_A); /* char as char */
printf("c_a repr: %c \n", c_a);
printf("c_return repr: %c \n", c_return);
return 0;
}
result:
int: 48 char: 0
int: 49 char: 1
int: 50 char: 2
int: 51 char: 3
int: 52 char: 4
int: 53 char: 5
int: 54 char: 6
int: 55 char: 7
int: 56 char: 8
int: 57 char: 9
c= 0123456789
c_A= 65
c_a= 97
c_return= 10
c_A repr: A
c_a repr: a
c_return repr:
Then I use instead:
int i;
char c[]="0123456789";
...
to assign values to c and got the same output. Thus,
is an array of characters such as c[10] defined above also a string? If it's true, then a string is an array holding characters (one char per element), and the value of c[i], i=0,9 can be promoted to be an integer?