answersLogoWhite

0

A compound statement is a code block. We typically use compound statements as the body of

another statement, such as a while statement:

while (i >= 0)

{

a[i] = x;

++x;

--i;

}

Note that all compound statements are surrounded by braces {}.

User Avatar

Wiki User

8y ago

Still curious? Ask our experts.

Chat with our AI personalities

ProfessorProfessor
I will give you the most educated answer.
Chat with Professor
MaxineMaxine
I respect you enough to keep it real.
Chat with Maxine
BlakeBlake
As your older brother, I've been where you are—maybe not exactly, but close enough.
Chat with Blake
More answers

A compound statement is any statement that is enclosed in curly braces, often referred to as a statement block. The entire block is treated as being a single statement, but is actually composed of none or more individual statements. Variables instantiated within a compound statement are local to the statement and fall from scope when the statement ends.

// Example of a simple statement:

for( int i=1; i<=10; ++i ) std::cout<<i<<std::endl;

// Example of a compound statement:

for( int i=1; i<=10; ++i ) {

int x=i*2;

std::cout<<x<<std::endl;

}

Compound statements may contain no statements at all. This is often encountered when using reverse logic:

if( x )

{} // compound statement

else

x=2;

The above is more typically written (and is easier to read) as a simple statement, as follows:

if( !x )

x=2;

User Avatar

Wiki User

11y ago
User Avatar

I dont exactly know what you mean but int x = 2; is a statement...

User Avatar

Wiki User

14y ago
User Avatar

Add your answer:

Earn +20 pts
Q: What is compound statement in c plus plus program?
Write your answer...
Submit
Still have questions?
magnify glass
imp