Q.The textbook illustrates assigning values to variables within the declaration section (initialization), where the declaration consists of a data type, a variable name, an equal sign, a number and a semicolon:
int x = 1;
char ch = 'y';
double r = 0.1234e-4
int x = 1;
char ch = 'y';
double r = 0.1234e-4
You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.
Start your 14-day free trial to unlock the full solution →[!TLDR]
A variable can be given its initial value in the same statement that declares it — this is called initialization.
When values are assigned within the declaration section, the declaration consists of a data type, a variable name, an equal sign, a value and a semicolon. Here int x = 1; declares x as an integer and stores 1 in it; char ch = 'y'; declares ch as a character and stores the character 'y' (character constants are written between apostrophes); and double r = 0.1234e-4; declares r as a double-precision real number holding . Initializing at the point of declaration guarantees the variable starts with a known value rather than an unpredi …
Unlock everything free for 14 days
- Full step-by-step solutions
- Concept-first explanations
- Methods, shortcuts & mistakes
- PYQ mapping + timed mock tests
Full access for 14 days. No credit card required.