ProgrammingVery hardProduct company OA
What is printed?
What is printed?
void rev(char *s, int i, int j) {
if (i >= j) return;
char t = s[i]; s[i] = s[j]; s[j] = t;
rev(s, i + 2, j - 2);
}
int main(void) {
char s[] = "ABCDEFGH";
rev(s, 0, 7);
printf("%s", s);
}- A. HBFDECGA
- B. HBFDEGCA
- C. HBCDEFGA
- D. HGFEDCBA
Correct answer: A. HBFDECGA
The steps of 2 swap only (0, 7) and (2, 5); the next call has i = 4, j = 3 and stops. So A↔H and C↔F: H B F D E C G A. 'HGFEDCBA' is a full reversal with steps of 1.
More C Programming questions
- Why are multi-statement macros usually written as #define M(x) do { ... } while (0)?
- What is printed? c #define INC(x) x++; x++ int a = 0, b = 0; if (a > 5) INC(b); printf("%d", b);
- What is printed? c int x = 7 / 2 2.0; double y = 7 / 2.0 2; printf("%d %.1f", x, y);
- What is printed? c void move(int pp) { (pp)++; pp += 10; } int main(void) { int a[] = {1, 2, 3}; int p = a; move(&p); move(&p); printf("%d…
- Assume 32-bit unsigned int. What is printed? c unsigned x = 0xABCD; printf("%X %X", (x >> 4) & 0xF, (x & ~(0xFu << 8)) | (0x3u << 8));
- In C99, which declaration lets you allocate a rows × cols matrix of int (cols known at run time) with ONE malloc, use it as m[i][j], and…