Sunday, September 13, 2020

Conditional operator Statement(? :)

C-language has an unusual operator, useful for making two=way deciaions. 

The operator is a combination ( ? ) and ( : ) and this operand.

This operator is known as conditional operator.

The general form of this operator is:

Conditional expression ( ? ) expression1 ( : ) 
expressional2

The conditional expression is value test first.
If the result is true, expressional is evaluated and is returned as the value the conditional expressional .Otherwise expression2 is evaluated and it is value is returned consider the following example

Y = 1.5x+3 for x<=2
Y = 2x+5   for x>2

This can be evaluated using the conditional operator statement as

Y = (x>2) ? (2*x+5) : (1.5*x+3);

goto statement : 
  
C supports the goto stayement to branch unconditionally from one point to another i the program.

The goto requires a lable in order to identify the place where the branch is to be made , label is any valid variable name, and must be followed by colon( : ).

The label is placed immediately before the statement where control is to be transferred.

The general form of goto statement is :

goto label ;                      label: statement 
. . . . . . . . . .                        . . . . . . . . . . . . . . . 
. . . . . . . . . .                        . . . . . . . . . . . . . . . 
. . . . . . . . . .                        . . . . . . . . . .  . . . . .
label: statement ;           goto label ;

forward jump                 backward jump

3 comments:

Object Paradigm Oriented Programming in C++ / object oriented programming / History of C++/ paradiagram in c++/C devolop, Operating System, Unix operating system, Assembly language, popular in world, Programming language.

  Object Paradigm Oriented Programming  Two programmers, Brian Kernighan and Dennis Ritchie developed a new language called C, in 1972.  C l...