You are on page 1of 2

ANSWERS LAB 1 QUESTIONS Q1: Invalid identifires are : 2014 park, double, king%kong Q2: ERROR: Cannot change

value of PI because it is a constant.

Q3: The #define directive is a preprocessor directive; the preprocessor replaces those macros by
their body before the compiler even sees it. Think of it as an automatic search and replace of your source code. A const variable declaration declares an actual variable in the language, which you can use... well, like a real variable: take its address, pass it around, use cast it, convert it, etc. Performance: Perhaps you're thinking that avoiding the declaration of a variable saves time and space, but with any sensible compiler optimisation levels there will be no difference, as constant values are already substituted and folded at compile time. But you gain the huge advantage of type checking and making your code known to the debugger, so there's really no reason not to use const variables.

Q4: For example: Please input radius 10 The area is 314.159 Q5:
#include <iostream> using namespace std; int main( ) { double x, y, area; // Step 1: Ask user to input sides of rectangle cout << "Please input sides of rectangle " << endl; cin >> x; cin >> y; // Step 2: Compute area area = x * y; // Step 3: Display the area cout << "The area is " << area << endl; return 0; }

Q6: 40 -215=-32768 -214-1=-16383 Q7: 5 4 Q8: 08 0x3H

Q9: Output: 2 2.4 12.5 12 Q10: There is an error. Cannot use % operator with floating point values.

You might also like