ProgrammingHardGATE CS
What is printed?
What is printed?
int a = -1;
unsigned int b = 1;
printf("%d %d", a < b, a < (int)b);- A. 1 1
- B. 1 0
- C. 0 0
- D. 0 1
Correct answer: D. 0 1
In a < b the signed -1 is converted to unsigned (a huge value), so it is false; with the cast both are signed and -1 < 1.
More C Programming questions
- What is printed? c int f(int n) { return n <= 1 ? 1 : f(n - 1) + f(n - 2) + n; } int main(void) { printf("%d", f(5)); return 0; }
- What is printed? c void g(int a[]) { printf("%d ", (int)(sizeof(a) == sizeof(int ))); } int main(void) { int a[10]; g(a); printf("%zu"…
- What is printed? c char s[20] = "abc"; strcat(s, "de"); strncpy(s + 1, "XYZW", 2); printf("%s %zu", s, strlen(s));
- What is printed? c int n = printf("ab%d", 123); printf(" %d", n);
- What is printed? c enum { A, B = 5, C, D = C + 2, E }; printf("%d %d %d", C, D, E);
- What is printed? c unsigned int x = 0xB4; printf("%u %u", x & -x, x & (x - 1));