ProgrammingModerateTCS NQT · Accenture
What is printed?
What is printed?
#include <stdio.h>
int main(void) {
int c = 0;
for (int i = 0, j = 10; i < j; i += 2, j--)
c++;
printf("%d", c);
}- A. 5
- B. 3
- C. 6
- D. 4
Correct answer: D. 4
The loop runs for (i, j) = (0, 10), (2, 9), (4, 8) and (6, 7), and then i = 8 and j = 6 fail the test. So c = 4.
More C Programming questions
- char b[5]; int n = snprintf(b, sizeof b, "%s", "abcdefgh"); printf("%s %d", b, n); What is printed?
- char buf[4]; int n = snprintf(buf, sizeof buf, "%d", 12345); printf("%d %s", n, buf); What is printed?
- char s[8] = "ab"; strncat(s, "cdefgh", 2); printf("%zu", strlen(s)); What is printed?
- char line[6]; fgets(line, sizeof line, stdin); / stdin holds the text 12345678 followed by a newline / printf("%zu", strlen(line)); What…
- char buf[7] = "hello"; memmove(buf + 1, buf, 5); printf("%s", buf); What is printed?
- char s[] = "one two three"; int w = 0; for (char t = strtok(s, " "); t; t = strtok(NULL, " ")) w++; printf("%d", w); What is printed?