answersLogoWhite

0


Best Answer

selection Also called a decision, one of the three basic logic structures in computerprogramming. The other two logic structures are sequence and loop.

In a selection structure, a question is asked, and depending on the answer, the program takes one of two courses of action, after which the program moves on to the next event.

This structure is sometimes referred to as an if-then-else because it directs the program to perform in this way: If Condition A is True then perform Action X else perform Action Y.

All logic problems in programming can be solved by forming algorithms using only the three logic structures, and they can be combined in an infinite number of ways. The more complex the computing need, the more complex the combination of structures.

User Avatar

Wiki User

11y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

6y ago

We use selection statements to control the flow of execution.

The simplest selection statement is the if statement, which has two forms:

if (expression) {

statement;

}

if (expression) {

statement; } else { statement;

}

In both forms, when the controlling expression evaluates true, control passes to the controlled statement. In the second form, when the controlling expression evaluates false, control passes to the elseclause. The else clause may be controlled by another if statement (a nested if):

if (expression) {

statement;

} else if (expression) {

statement;

} else {

// ...

}

Here, the second statement only executes when the first expression evaluates false and the second expression evaluates true. If both are false, control passes to the next else clause (if any).

The switch statement allows us greater control over the flow of execution. Rather than evaluating true or false, the control expression must evaluate to a value of integral type or enumeration:

switch (expression) {

case 0: statement;

case 1: statement;

case 2: statement;

default: statement;

}

Here, the evaluation of the expression determines which case label we jump to. Execution then continues from that point until a break, return or goto statement is encountered. The default case is optional, but can be used to cater for all evaluations not handled by an explicit case. Moreover, the default case need not be the final case label.

The switch statement is most useful when selecting between enumerations:

enum traffic_light {red, amber, green};

const char* traffic_light_string (traffic_light colour) {

switch (colour) {

case red: return "Red";

case amber: return "Amber";

case green: return "Green";

}

}

We don't use a default case here because the cases alone cover all possibilities. This also gives the compiler an opportunity to check all cases really are covered; if we "forget" an enumeration (particularly with a larger enumeration), the compiler can warn us of the fact. If we include a default, we lose that ability.

The final selection statement is the conditional (ternary) operator. It is ternary because it has three operands. We use this operator to choose between two expressions (rather than two statements):

char* f (int x) {

return x==0 ? "x is zero" : "x is non-zero";

}

In this example, the function evaluates the control expression (x==0). If true, the first expression is evaluated, otherwise the second expression is evaluated.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What does mean selection in c program?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Is there any c program that could read c program too?

I don't really understand your question, but maybe it is the compiler what you mean.


What do you mean by c taken programming in c?

A C program is a computer program written using the C programming language.


C program was introduced in the year?

c program was introduced in the year 1972 by Dennis RitchieNo, it was the C language, not the C program.


Can you explain the program of Fibonacci series in c?

You mean you have written a program, but you don't understand it? Well, how could I explain it without seeing it?


When you make a c program in c language then how many types class are required?

It depends on what you mean by 'types class'. Here is the shortest C program, without any 'types class': int main (void) { return 0; }

Related questions

Write a c program Fibonacci series using for loop in java?

Exactly what do you mean by 'C program in Java'


Who is father of c program?

If you mean who designed C, then that would be Dennis Ritchie.


Is there any c program that could read c program too?

I don't really understand your question, but maybe it is the compiler what you mean.


C program to find the mean median mode?

try this---> http://c-pgms.blogspot.com/2008/08/program-to-find-meanmedianand-mode_22.html


What do you mean by c taken programming in c?

A C program is a computer program written using the C programming language.


Write a c program to exit?

Not sure what you mean by this question - using the exit call will exit a C program:exit (0) ;


C program was introduced in the year?

c program was introduced in the year 1972 by Dennis RitchieNo, it was the C language, not the C program.


Features of c program?

the features of a C program


Can you explain the program of Fibonacci series in c?

You mean you have written a program, but you don't understand it? Well, how could I explain it without seeing it?


Can you change the name of function in c program?

In the source, you mean? Use a text-editor.


What do the letters L R C P mean?

London Regional Cancer Program.


Enumerate the types of selection constructs in c plus plus?

Selection constructs in C++if...elseswitch/caseconditional ternary operator (?:)