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 sample contains equal numbers of two isotopes X and Y, each with half-lives of 10 days and 20 days respectively. What is the ratio of activities Aâ‚“ ...
When a liquid is heated in a container, which of the following processes primarily causes the heat transfer within the liquid? Â
A mass of 0.1 kg executes SHM with amplitude 10 cm. Its kinetic energy at the mean position is 8 × 10-3 J. What is its equation of motion if...
The focal length of a concave mirror is 20 cm. Where should an object be placed to get an image of the same size?
Which law states that the ratio of the potential difference across a conductor to the current through it is constant, provided the temperature remains c...
The term ‘Isoneph' indicates the lines of equal –
When a cannonball is fired, its motion is an example of ______.
An image formed by a plane mirror is ______.
A transformer has 1000 turns in the primary and 100 in the secondary coil. If input voltage is 220 V, output voltage is:
Which of the following statement is correct?
I. Value of ‘g’ is higher at poles than equator
II. Weight of an object at moon is 1...