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.
A trader marked an article 50% above its cost price and sold it after allowing a discount of 30%. If the transaction resulted in a profit of Rs. 26, the...
In a quadrilateral ABCD, the diagonals AC and BD intersect at O. If AO = 8 cm, OC = 12 cm, BO = 6 cm, and OD = 9 cm, find the area of the quadrilateral ...
The ratio of the angles of a quadrilateral is 3:2:7:8. What is the sum of the largest and the smallest angle?
The length of the diagonal of a rhombus is 24 cm, and the perimeter is 80 cm. Find the area of the rhombus.
What is 4(a³b ⁶ ) 16 × 16(a ⁴ b²)2 equal to?
The area (in square units) of the quadrilateral ABCD, formed by the vertices A (0, -2), B (2, 1), C (0, 4), and D (-2, 1) is: