Question
What will be the output of the following C code?
#include < stdio.h > void main ( ) { Â Â int x = 10, y = 20, *p1 = &x, *p2 = &y; Â Â *p2 = *p1 + *p2; Â Â printf ("%d %d\n", x, y); }Solution
The code demonstrates pointer manipulation in C. Here’s a breakdown: • int x = 10, y = 20; declares two integers, x and y. • *p1 = &x, *p2 = &y; initializes p1 to point to x and p2 to point to y. • *p2 = *p1 + *p2; fetches the values of x and y through p1 and p2 respectively, adds them, and assigns the result back to y via *p2. After this operation, y becomes 30, while x remains 10. Output: 10 30. Why Other Options Are Incorrect: 1. 10 20: This would occur if no pointer manipulation happened, but the code modifies y. 2. 30 10: Only y is updated, not x. 3. Compiler error: The code is syntactically correct and compiles successfully. 4. Undefined behavior: The pointers are used properly with valid memory addresses, avoiding undefined behavior.
Find the unit digit of (57 129 Â - 7).
Find the difference between of the greatest among the numbers 0.82, 0.802, 0.85, 0.085 with the smallest among the numbers 0.3, 0.03, 0.203, 2.03
The number of chocolates with ‘Rohan’ and ‘Sohan’ together is 20 more than that with ‘Mohan’, while the number of chocolates with ‘Sohan�...
A number when divided by 25 leaves a remainder of 19. What will be the remainder when five times that number is divided by 25?
What is the smallest four-digit number that can be evenly divided by 20, 24, and 36?
- Find the smallest perfect square that is divisible by 10, 14, 18, and 21. What is the remainder when it is divided by 85?
A, B and C hired a taxi for Rs. 880 and used it for 2, 4, 5 hours respectively. Hiring charges paid by B are:
The number of present boys to girls is in the ratio 2:1. If 15 girls are absent and they form 25% of the total class, and no boy is absent, then find th...
One baker house has to make 600 cakes and another one 750 cakes during the same period of time. In the first house, the order was ready 5 days ahead of ...