ProgrammingHard
char a[] = "Level"; int pal = 1; for (int i = 0, j = 4; i < j; i++, j--) if (a[i] != a[j]) pal = 0; printf("%d", pal); What is printed?
- A. 1
- B. 2
- C. 3
- D. 0
Correct answer: D. 0
L and l differ in case, so the case-sensitive test fails at the first pair and pal becomes 0.
More C Programming questions
- char a[] = "Level"; int pal = 1; for (int i = 0, j = 4; i < j; i++, j--) if (tolower(a[i]) != tolower(a[j])) pal = 0; printf("%d", pal)…
- printf("[%-6s|]", "ab"); What is printed?
- printf("%+d %05.1f", 5, 3.14159); What is printed?
- char s[] = "abc"; printf("%c", s[strlen(s) - 1]); What is printed?
- char w[] = "ab"; printf("%zu %zu", sizeof w, strlen(w)); What is printed (on any platform)?
- char a = "cat"; char b[] = "cat"; printf("%d", strcmp(a, b) == 0); What is printed?