May 2012
Intermediate to advanced
679 pages
16h 56m
English
A compound statement consists of any number of statements put inside curly brackets3. Anything put inside the braces is treated by C++ as a block. Block is little more than a compound statement. Concept of block has come from old language called ALGOL. C++ allows you to declare variables inside a block4. The scope of such variable is restricted to that block only. Let us study the concept with help of a simple program.
Problem: Write a program to demonstrate block structure.
Solution: Here we will define one variable inside the block and see whether it is available outside the block. We will test whether we can declare a variable at a place other than the beginning of the block. See Program 2.6.
Read now
Unlock full access