char p[] = "robert" char *q = "robert" |
printf("%s\n", p); printf("%s\n", q); printf("%c\n", *p); printf("%c\n", *q); printf("%c\n", p[0]); printf("%c\n", q[0]); printf("%c\n", *(p+1)); printf("%c\n", (*p)+1); |
p[0] = 'R'; *q = 'R'; |
What will be the result of the following 'copy' instructions?
p = q; |
q = p; |
char r[5] = "junk"; char s[2] = "a0"; char t[3] = "b1"; |
printf("%s\n", r); printf("%s\n", s); printf("%s\n", t); |
char *days1[] = {"monday", "tuesday", "wednesday"}; char days2[][9] = {"monday", "tuesday", "wednesday"}; |
In the following table a number of arrays have been defined. Fill in the minimum index, maximum index, sizeof() each element and sizeof() the whole data structure in each case.
Data structure | Min. | Max. | sizeof() element | sizeof() structure |
char str[50]; | ||||
int counts[100]; | ||||
double temps[31]; | ||||
int m[20][50]; | ||||
char *names[20]; | ||||
char *argv[]; |
Suppose that the C declaration
int A[4] = {1, 256, 65536, 16777216}; |
Write two different versions of the C standard library function to determine the length of a string, where the function has the interface:
int strlen(char *str); |