ProgrammingModerate
char *s = "abc"; char t[4]; strcpy(t, s); t[1] = 'X'; printf("%s", t); What is printed?
- A. abc
- B. aXc
- C. Xbc
- D. aXX
Correct answer: B. aXc
strcpy copies the four bytes of abc with its terminator into t, and t[1] is then replaced by X.
More C Programming questions
- char buf[5] = "abcd"; buf[4] = 'e'; printf("%.5s", buf); What is printed (no terminator is present, which is defined)?
- char s[] = "AbC"; for (char p = s; p; p++) p = isupper((unsigned char)p) ? tolower((unsigned char)p) : toupper((unsigned char)p)…
- int count = 0; for (const char p = "a1b22c"; p; p++) if (isdigit((unsigned char)p)) count++; printf("%d", count); What is printed?
- char name[8] = "Sam"; printf("%d %d", (int)sizeof name, (int)strlen(name)); What is printed?
- char s[] = "12345"; int v = 0; for (int i = 0; s[i]; i++) v = v 10 + (s[i] - '0'); printf("%d", v); What is printed?
- char s[] = "ab"; char q = s + 2; printf("%d", q); What is printed?