Conditional or Ternary Operator (?:) in C - learnit

Home Top Ad

Post Top Ad

Saturday, June 5, 2021

Conditional or Ternary Operator (?:) in C

How to Create Class Modules

What is C Programming?

C programming is a general-purpose , procedural, imperative computer programming language developed in 1972 by Dennis M. Ritchie at the Bell Telephone Laboratories to develop the UNIX operating system. C is the most widely used computer language. It keeps fluctuating at number one scale of popularity along with Java programming language, which is also equally popular and most widely used among modern software programmers.


Why to Learn C Programming?

C programming language is a MUST for students and working professionals to become a great Software Engineer specially when they are working in Software Development Domain. I will list down some of the key advantages of learning C Programming:


-C++ is used to develop games, desktop apps, operating systems, browsers, and so on because of its performance.


-After learning C++, it will be much easier to learn other programming languages like Java, Python, etc.


-C++ helps you to understand the internal architecture of a computer, how computer stores and retrieves information.


-Easy to learn

-Structured language

-It produces efficient programs

-It can handle low-level activities

-It can be compiled on a variety of computer platforms


Conditional or Ternary Operator (?:) in C

The conditional operator is somewhat similar to the if-else statement as it does follow the same algorithm as of if-else statement but the conditional operator takes less space and helps to write the if-else statements in the shortest way possible.


Syntax

The conditional operator is of the form

variable = Expression1 ? Expression2 : Expression3

Example

10>20? Printf(“Failed”):Printf(“Passed”)

It can be visualized into if-else statement as:

if(Expression1)
{
variable = Expression2;
}
else
{
variable = Expression3;
}


Example

Example

#include <stdio.h>
#include <conio.h>
int main()
{
int score;
printf("Please input score\n");
scanf("%d", &score);
(score >=0 && score < 50)? printf("Failed\n"):printf("Passed\n");
getch();
}

Please Watching My Video is Below

No comments:

Post a Comment

Post Top Ad