ProgrammingHardTCS NQT · Infosys pattern
What is printed?
What is printed?
int main(void) {
char ch = 'A';
int code = ch + 1;
printf("%d %c", code, (char)code);
}- A. 65 A
- B. 66 A
- C. 65 B
- D. 66 B
Correct answer: D. 66 B
ch promotes to int for the addition: 'A' is 65, +1 = 66. Printed as %d, that's 66; cast back to char and printed as %c, 66 is the character 'B'.
More C Programming questions
- What is printed? c int main(void) { int n = 17; int isPrime = 1; for (int i = 2; i i <= n; i++) { if (n % i == 0) { isPrime = 0; break; }…
- What is printed? c int main(void) { int a = 5; int b = a; b = b + 10; int p = &a; p = p + 100; printf("%d %d", a, b); }
- Assume a 64-bit LP64 ABI. What is printed? c struct Matrix3x3 { int data[3][3]; }; int trace(struct Matrix3x3 m) { int sum = 0; for (int i…
- Assume 32-bit int. What is printed? c int a = 5; int b = a > 0 ? 1 : a < 0 ? -1 : 0; int c = -5; int d = c > 0 ? 1 : c < 0 ? -1 : 0…
- Assume 32-bit int. What is printed? c int x = 100; int y = x / 3 3; int z = x % 3; printf("%d %d", y, z);
- What happens when this runs? c int p = malloc(sizeof(int) 5); if (p) { for (int i = 0; i < 5; i++) p[i] = i; } int q = realloc(p…