ProgrammingHardTCS NQT · Infosys pattern
What is printed?
What is printed?
int main(void) {
int a = 5;
int b = a;
b = b + 10;
int *p = &a;
*p = *p + 100;
printf("%d %d", a, b);
}- A. 105 15
- B. 5 15
- C. 105 5
- D. 15 105
Correct answer: A. 105 15
b is an independent copy of a's original value (5), so b=5+10=15 never affects a. Separately, modifying a through pointer p (*p = *p+100) changes a directly to 5+100=105. Final: a=105, b=15.
More C Programming questions
- Assume a 64-bit LP64 ABI. What is printed? c struct Matrix3x3 { int data[3][3]; }; int trace(struct Matrix3x3 m) { int sum = 0; for (int i…
- Assume 32-bit int. What is printed? c int a = 5; int b = a > 0 ? 1 : a < 0 ? -1 : 0; int c = -5; int d = c > 0 ? 1 : c < 0 ? -1 : 0…
- Assume 32-bit int. What is printed? c int x = 100; int y = x / 3 3; int z = x % 3; printf("%d %d", y, z);
- What happens when this runs? c int p = malloc(sizeof(int) 5); if (p) { for (int i = 0; i < 5; i++) p[i] = i; } int q = realloc(p…
- Assume 32-bit int. What is printed? c int arr[5] = {1, 2, 3, 4, 5}; int p = arr; int sum1 = arr[2] + (arr + 2); int sum2 = (p + 2) + p[2]…
- What is printed? c #define SIGN(x) ((x) > 0 ? 1 : (x) < 0 ? -1 : 0) int main(void) { int values[3] = {-5, 0, 7}; for (int i = 0; i < 3…