ProgrammingHardTCS NQT · Infosys
What is printed?
What is printed?
#include <stdio.h>
int main(void) {
unsigned char c = 255;
c += 1;
printf("%d", c);
}- A. 0
- B. 1
- C. 256
- D. 255
Correct answer: A. 0
c + 1 is 256 in int, and storing it back in unsigned char wraps the value to 0.
More C Programming questions
- Assume int and unsigned int are 32-bit. What does this program print? #include <stdio.h> int main(void) { unsigned int a = 3; int b = -5…
- What does this program print? #include <stdio.h> int main(void) { int a[] = {10, 20, 30, 40, 50}; int p = a + 1; int v = p++; int w = ++p…
- What does this C program print? unsigned char a = 200, b = 100; printf("%d %d", a + b > 255, (unsigned char)(a + b) > 255);
- What does this C program print? int a[2][3] = {{1,2,3},{4,5,6}}; int (p)[3] = a; printf("%d %d", ((p+1))[1], (p+1) + (p+2));
- What does this C program print? #define SQ(x) xx printf("%d", SQ(2+3) / SQ(1+1));
- What is printed? int f(int n) { static int c = 0; c += n; if (n <= 0) return c; int r = f(n - 1); return r + c; } printf("%d", f(3));