ProgrammingHard
printf("%c", 321); What is printed?
- A. B
- B. 1
- C. nothing, because 321 is out of range
- D. A
Correct answer: D. A
The %c conversion converts the int to unsigned char, so 321 is reduced modulo 256 to 65, which is 'A' in ASCII.
More C Programming questions
- char a[20], b[20]; / stdin: "hi therennextn" / scanf("%s", a); fgets(b, sizeof b, stdin); What is stored in b?
- char w[] = "ab", z[2] = "ab"; printf("%zu", sizeof w + sizeof z); What is printed?
- For a string s of length up to 2 x 10^5 stored in a char array, which in-place reversal is correct and fast enough?
- What is the value of sizeof("hello") in C?
- char buf[] = "abcn"; buf[strcspn(buf, "n")] = '0'; printf("%zu", strlen(buf)); What is printed?
- Why must the result of getchar() be stored in an int rather than a char?