answersLogoWhite

0

A compound statement is any statement that contains zero or more statements. If there is more than one statement in a compound statement, they must be enclosed in braces {}, otherwise braces are optional with the exception of function bodies (which must always be enclosed in braces, regardless of the number of statements they contain).

For example, the if statement has the following syntax:

if( expression ) statement1 [elsestatement2]

Either statement may be a compound statement containing zero or more statements (including other if statements). For instance, suppose x is a random signed integer:

if( x<=0 )

{

// Compound statement with no statements.

// The braces are optional here.

}

else if( x%2 )

{

// compound statement with one statement.

// The braces are optional here too.

std::cout << x " is odd" << std::endl;

}

else if( x >= 100)

{

// Compound statement with 2 statements.

// Braces are not optional here.

std::cout << x " is even" << std::endl;

std::cout << x " is greater than or equal to 100" << std::endl;

}

else if( x%4==0 )

{

// Compound statement with 3 statements.

// Braces are not optional here.

std::cout << x " is even" << std::endl;

std::cout << x " is less than 100 but greater than 0" << std::endl;

std::cout << x " is a multiple of 4" << std::endl;

}

END:

User Avatar

Wiki User

13y ago

What else can I help you with?

Related Questions

What is a block in c plus plus?

Assuming you mean a code block, a group of simple statements enclosed in braces {} is regarded as a code block. In other words, a compound statement. Braces are not required around simple statements except when the statement is the body of a function (where braces are mandatory).


What does a statement in c plus plus end with?

A simple statement ends with a semi-colon (';'). A compound statement contains one or more simple statements (with semi-colon terminators) enclosed within opening and closing braces ('{' and '}').


What are the conditional statement of turbo c plus plus dos based?

Statements that check an expression then may or may not execute a statement or group of statements depending on the result of the condition.


Which statement is not frequently used in C plus plus?

The goto statement.


Is C function a compound statement?

yes


What is the deffernce of the switch statement and the if statement in c plus plus?

If statement is single selection statement,whereas the switch statement is multiple selective.


How do you write a arithmetic operations in c using compound assignment statement?

a = b = c


Basic control structure available in c plus plus?

The basic control structure in C++ is the if statement.


What is the compound in this group C O HCl Hg?

HCl is a compound, C, O, Hg are elements


What is compound statement in c plus plus program?

A compound statement is a code block. We typically use compound statements as the body ofanother statement, such as a while statement:while (i >= 0){a[i] = x;++x;--i;}Note that all compound statements are surrounded by braces {}.


A c plus plus statement that invokes a function is known as?

...a function call.


What is a compound statement?

A compound statement consists of none or more C++ statements enclosed within a set of braces: {}. It is an essential concept in C++ and is central to the idea of nesting constructs. For example, the if statement has the form:-if ( expression ) statementwhich would severely limit its use were it not for the fact that a compound statement is itself a statement. Consequently any number of statements can be enclosed within a set of braces, including other if and compound ones, and the resulting compound statement used with the if statement. For example:-