Question
What is the purpose of the #define directive in
programming languages like C and C++?Solution
The #define directive in C and C++ is a preprocessor command used to define macros. Macros can be constants or code snippets that are substituted into the program wherever they are referenced. For example, #define PI 3.14 defines a constant named PI with the value 3.14 . Similarly, #define SQUARE(x) ((x) * (x)) defines a macro for computing the square of a number. This directive helps in making the code more readable, manageable, and easier to maintain by avoiding the repetition of constants and code fragments. It operates at the preprocessing stage before the actual compilation of the code begins.
In a 550-metre race, βAβ beats βBβ by 12 seconds or 60 metres. Find the time taken by βBβ to finish the race.
- A cyclist covered a distance in two parts: first 1.5 hours at 32 km/h and then 2.5 hours at 48 km/h. What was the average speed for the complete journey?
βEβ and βFβ started moving towards each other at the same time with a speed of 30 km/hr and 25 km/hr, respectively. If the distance covered by οΏ½...
- How far will 'Puneet' travel by the time he catches up to 'Bittu', given that 'Puneet' starts 90 km behind and moves at 45 km/h while 'Bittu' moves at 30 k...
Pranav went to the bank at the speed of 60 km/h while returning for his home he covered the half of the distance at the speed of 10 km/h, but suddenly h...
A man travelled a total distance of 300 km. He travelled first 100 km on car with a speed of 20 km/h and rest of the distance on bike whose speed is 10 ...
- Sita takes 6 hours to walk from village 'D' to village 'E' at a speed of 5 km/h. Then she increases her speed by 60% and takes 2 hours to reach village 'F'...
A was travelling from point X to point Y. He increased his speed by 20 km/h after every hour. He reached his destination in 14 hours. If his initial spe...
A train crosses a pole in 12 sec, and a bridge of length 170 m in 36 sec. Then the speed of the train is:
If a person walks 25% more than of his usual speed, reaches his distance 90 minutes before. If the destination is 495 km away, then the usual speed of a...