ProgrammingModerateTCS NQT · Infosys
What is printed?
What is printed?
int score = 73;
char g = score >= 90 ? 'A' : score >= 75 ? 'B' : score >= 60 ? 'C' : 'D';
printf("%c%d", g, g - 'A');- A. C2
- B. C3
- C. D3
- D. B1
Correct answer: A. C2
The conditionals nest to the right and are tested in order: 73 fails ≥ 90 and ≥ 75 and passes ≥ 60, so g = 'C'. 'C' − 'A' = 2 in any character set where the capital letters are consecutive, as in ASCII.
More C Programming questions
- Which of these statements about C (not C++) are true? (i) A const int variable at file scope is a constant expression, so it can size a…
- Which of these is NOT allowed for a variable declared with the register storage class in C?
- What does p(5) print? c void p(int n) { if (n <= 0) return; p(n - 2); printf("%d", n); p(n - 3); }
- Which statement about this C declaration is true? c char a[5] = "hello";
- What is printed? c #define CUBE(x) ((x) (x) (x)) int n = 0; int f(void) { n++; return 2; } int main(void) { int r = CUBE(f()); printf("%d…
- What is printed? c unsigned char rotl(unsigned char v, int k) { return (unsigned char)(v << k | v >> (8 - k)); } int main(void) {…