#10: Ternary Operator in C | C Programming for Beginners

preview_player
Показать описание
Step by step video tutorials to learn C Programming for absolute beginners!

In this video, we will learn about the ternary operator in C with their syntax and examples. We will also learn some of the cases, where we can replace the if...else statement with a ternary operator and see how the ternary operator will make our code cleaner and shorter.

~

Watch our videos and revise them with our C App!

Timestamps:
00:00 Start
00:53 Example: Ternary Operator
04:33 Ternary Operator Vs if...else Statement
05:37 Programming Task
06:18 Quiz

------------------------------

Find Programiz elsewhere:

#programiz #learncprogramming #learnc #coding #ctutorial #ternary #operator #conditionaloperator #ifelse #coperator #programming
Рекомендации по теме
Комментарии
Автор

🔥Finding it Damn Hard to Understand C Programming?
Learn to code—the right way—with interactive lessons, quizzes & challenges. Build a strong programming base; it's IMPORTANT!

programizstudios
Автор

/*
Can you create a program to check whether a number is odd or eve?
> Use a ternary operator to check if the number is odd or even.
> If number is odd, print "The number is Odd"
> If number is even, print "The number is Even"
*/

#include <stdio.h>

int main() {

int number;

printf("Enter a number: ");
scanf("%d", &number);

// by using Ternary Operator
(number % 2==0) ? printf("The number is Even") : printf("The number is Odd");
}

AlaskarAbdoul
Автор

Programming Task:
#include <stdio.h>

int main() {
int number;
printf("Enter a number: ");
scanf("%d", &number);

(number%2 == 0) ? printf("%d is an even number.", number) : printf("%d is an odd number.", number);

return 0;

}

hurulaynmuhamedsalimcedarp
Автор

You did an excellent job explaining the switch statement. I was and am still amazed at how easy you made this so understandable. Please continue teaching us. You have an absolute gift in how you explain these concepts. Thank you sooo much!

michaelspencer
Автор

//Can you create a program to check whether a number is odd or even?
//***Use a ternary operator to check if the number is odd or even
//***If the number is odd print the number is odd
//***If the number is even print the number is even

#include <stdio.h>

int main() {

int number;

printf("Enter a number: ");
scanf("%d", &number);

(number % 2==0) ? printf("The number is Even.") : printf("The number is Odd.");

return 0;
}

rhythmahmed
Автор

Answer is option c
Result=5>3 ? 5 : 3;

SANJAYR-yyzg
Автор

Your tutorials are so helpful. i learnt switch statement and im now learning tenrary operator. keep the great work up!

batmanelhakeky
Автор

for the quiz, it opts C coz in the if-else statement the if part is evaluated to be true and hence gives 5 so the same principle applies Ternary:- (CONDITION) ? Statement1(Executed when True) : Statement2(Executed when False)

rahulc.h
Автор

Really useful content I really want to thank the teachers who are making the classes

shankaradari
Автор

I tried this in front of my teacher and even he doesn't know about this operator. Thank U❤️❤️❤️

shohanurrahmanshoron
Автор

Thanks for providing this useful and & well content for us....
Code
#include <stdio.h>

int main()
{
int a;
scanf("%d", &a);

(a %2 ==0) ?
printf("%d is even", a):
printf("%d is odd", a);
}
Ans for Question is C.

sundeepchowdaryattaluri
Автор

B as we have to print Result = 5
but in C the value of just 5 is will be as output

adityasharma
Автор

#include <stdio.h>
int main();
{
Int number=2;
(number % 2 == 0) ? Printf("the number is even") : printf("the number is odd");
return 0 ;
}

rakesh
Автор

Love it, explantion was clear and straightforward, however, I suggest you also talk about how to implement nested Ternary operators.

Judyy.Sabryy
Автор

Thankyou for explaining it so simply.. was waiting for your video ❤️

sunangashilpakar
Автор

Thanks for providing " Good quality "content
By the way answer is option C

mdsahil
Автор

Thanks for explaining this code simply

qarikhalidwaheed
Автор

Beautiful 🤩
Thank you for explaining it so well

pristinewalek
Автор

Great explanation as always! Thank you for everyone to make this happen.

ntnmfbu
Автор

Mam your explanation is very good and nice, can you make a tutorial videos on Data structures and algorithms in good explanation based on c language.

kankarlabharath