ProgrammingHardGATE CS · TCS NQT
What is printed?
What is printed?
#include <stdio.h>
int main(void) {
int x = 1, y = 2;
const int *cp = &x;
int *const pc = &y;
*pc = 5;
printf("%d %d", *cp, y);
}- A. 5 2
- B. 1 2
- C. 5 5
- D. 1 5
Correct answer: D. 1 5
cp points at x and is never changed, while pc points at y, which the assignment *pc = 5 changes. The pointer itself is constant, but the int it points to is not.
More C Programming questions
- What is printed? Assume double is 8 bytes. c #include <stdio.h> int main(void) { printf("%zu", sizeof(1 ? 'a' : 1.0)); }
- What is printed? c #include <stdio.h> #include <stdlib.h> #include <string.h> int cmp(const void a, const void b) { return strcmp((const…
- What index is printed when bsearch looks up "cat" in the sorted array {"ant", "bee", "cat", "dog"}? c #include <stdio.h> #include…
- How many ordered ways are there to write 10 as a sum of 1s, 2s and 3s? Compute with this program. c #include <stdio.h> int f(int n) { if…
- What is printed? c #include <stdio.h> int main(void) { unsigned n = 44; while (n & (n - 1)) n &= n - 1; printf("%u", n); }
- What is printed? c #include <stdio.h> int main(void) { unsigned n = 0; printf("%d", (n & (n - 1)) == 0); }