ProgrammingHardProduct-company MCQ pattern
With ASCII and 4-byte int, what is printed?
With ASCII and 4-byte int, what is printed?
char c = 'A';
c = c + 32;
printf("%c %zu", c, sizeof(c + 1));- A. 97 1
- B. a 4
- C. A 4
- D. a 1
Correct answer: B. a 4
'A' + 32 = 97 = 'a', stored back in c. In c + 1 the char is promoted to int before the addition, so the expression has type int and sizeof gives 4, not 1.
More C Programming questions
- What is printed? c char s[] = "abcdef"; char p = s, q = s + strlen(s) - 1; while (p < q) p++ = q--; printf("%s", s);
- What is printed? c struct A { int a[2]; }; struct B { int p; }; int v = 5; struct A x = {{1, 2}}, y; struct B m = {&v}, n; y = x; n = m…
- With 4-byte int and 8-byte double aligned on 8 bytes, what is sizeof(union U)? c union U { int i; double d; char c[10]; };
- What is printed? c int nextid(void) { static int id = 0; return ++id; } int main(void) { int a = nextid(), b = nextid(), c = nextid()…
- What is printed? c int x = 2; switch (x) { case 1: printf("1"); case 2: printf("2"); case 3: printf("3"); break; default: printf("D"); }
- What is printed? c if (-1 < 1u) printf("yes"); else printf("no");