ProgrammingHardTCS NQT · Infosys

What is printed?

What is printed?
#include <ctype.h>
#include <stdio.h>
int main(void) {
    const char *s = "Hello World";
    int n = 0;
    for (const char *p = s; *p; p++)
        if (isalpha((unsigned char)*p) && (*p & 0x20) == 0) n++;
    printf("%d", n);
}
  1. A. 3
  2. B. 2
  3. C. 1
  4. D. 4

Correct answer: B. 2

Bit 0x20 is clear only in uppercase letters, and the uppercase letters of Hello World are H and W. So the count is 2.

More C Programming questions

Exams that ask this topic