ProgrammingHardWipro · Cognizant pattern
What is printed?
What is printed?
int main(void) {
int x = 1;
int *p = &x;
*p += 1;
(*p)++;
++*p;
printf("%d", x);
}- A. 4
- B. 3
- C. 2
- D. 1
Correct answer: A. 4
Starting x=1: *p += 1 makes x=2. (*p)++ post-increments the dereferenced value, making x=3. ++*p is equivalent to ++(*p), pre-incrementing to x=4. Final x=4.
More C Programming questions
- What is printed? c int main(void) { int x = 0; int y = (x = 5, x + 1); printf("%d %d", x, y); }
- What is printed? c int main(void) { int arr[3] = {1, 2, 3}; int p = arr; for (int i = 0; i < 3; i++, p++) { printf("%d ", p); } }
- Assume 32-bit int. What is printed? c int x = 7; int y = x > 5 && x < 10 ? x 2 : x + 1; printf("%d", y);
- What happens when this runs? c int p = malloc(10 sizeof(int)); for (int i = 0; i <= 10; i++) { p[i] = i; } free(p);
- Assume 32-bit int. What is printed? c int a = 6; int b = a++ 2; printf("%d %d", a, b);
- What is printed? c #define MAXSIZE 100 #if MAXSIZE > 50 const char label = "large"; #else const char label = "small"; #endif printf("%s"…