Conditional Operator in C

preview_player
Показать описание
C Programming & Data Structures: Conditional Operator in C
Topics discussed:
1. Introduction to Conditional Operator in C language.
2. Use of Conditional Operator.
3. Example of Conditional Operator.
4. Homework Problem.

Music:
Axol x Alex Skrindo - You [NCS Release]

#CProgrammingByNeso #CProgramming #ConditionalOperator
Рекомендации по теме
Комментарии
Автор

Ans will be 65.
Explanation:
lets break the problem into part
(1) At first the condition is sizeof(var)
if this condition is evaluated to be true then (var2>23 ? ((var==75) ? 'A' : 0) : 0) will be returned
if false then 0 will be returned

As we know sizeof() is an unary operator which returns how many byte a datatype can hold
as var is an variable of integer data type, sizeof(var) will either return 2 or 4 as machine to machine int vary . We know every number except 0 is evaluated to be true. So (var2>23 ? ((var==75) ? 'A' : 0) : 0) it will returned


(2)next the condition is (var2>23)
if this condition is evaluated to be true then ((var==75) ? 'A' : 0) will be returned
if false then 0 will be returned
as we know 56>23 is true then ((var==75) ? 'A' : 0) will be returned.


(3)the condition is (var==75)
if this condition is evaluated to be true then 'A' will be returned
if false then 0 will be returned


As 75==75 then 'A' will be returned and stored into num variable
As c support auto type casting so int can store char.


In the final printf function we use the placeholder %d and it print integer value .
According to Ascii integer value of 'A' is 65
So the output will be 65.

ProgrammingwithArijit
Автор

Answer -> 65
Solution ->
num = sizeof(var) ? (var2 > 23 ? ((var == 75) ? 'A' : 0) : 0) : 0;
as we know, var==75 is True, therefore, (var == 75) ? 'A' : 0 will be equal to 'A'.
Then we will replace the equation with 'A' in the main equation.
num = sizeof(var) ? (var2 > 23 ? 'A' : 0) : 0;
as we know, var2 == 56, hence greater than 23, therefore, var2 > 23 ? 'A' : 0 will be equal to 'A'.
Then we will replace the equation with 'A' in the main equation.
num = sizeof(var) ? 'A' : 0;
as we know, as condition is True if the result of expression is any number except 0, sizeof(var) == 4, as its an integer data type.
sizeof(var) is a True statement, therefore, sizeof(var) ? 'A' : 0 will be equal to 'A'.
This implies num = 'A';
In the printf statement, the format specifier of num is %d, so the ASCII value of the character will be printed. ASCII value of 'A' = 65.

ayushkumar
Автор

Interesting lectures and also they are making to think for every homework questions.

randomthief
Автор

O/p is 65 ... because all three condition are true...sizeof(var)
Shows the size of int (which is other than 0 ....and then after all condition are executed it will return A and the decimal of A is 65 ..
according to ASCII TABLE

pranaylambat
Автор

it will be wayyy better if you can explain the homework problems @nesoacademy sometimes I can't fully comprehend the answers

millenmarbun
Автор

Output will be the ASCI code of 'A' =65; Thank you for your efforts, I like your explanation so much ❤

justindenison
Автор

This question is like 10 questions in one question. Neso team is great.

rsingh
Автор

hands down this is the best channel . pls continue blessing us with valuable information.

soumi
Автор

Thanks for teaching me something in 5 minutes that my teacher took two 50 minutes classes for! 😃😃

gautam
Автор

The answer is 65
First we will solve the inner brackets. According to that our condition is true so it will store the corresponding value of A according to ASCII i.e. 65 (because we are dealing with integer datatype). Then we will work our way out solving the outer brackets one by one. Hence the final answer is 65.

wajahatriazmirza
Автор

okay guys, here is the point ..
if we considered it as an if statement, it'll be as following ; )
int var = 75, var2 = 65;
int num ;

if(sizeof(var))
{
if(var2 > 23)
{
if(var == 75)
{
num = 'A';
}
}
printf("%d", num);
}


else
return 0;


the output is gonna be 65, and this is according to ASCII table, as 'A' is = 65 ..

ahmedsedeek
Автор

Thanks a lot for videos sir ❣️. It's really helpful.

shashankpandey
Автор

Sir please solve homework problems also so that we can give it a try and if we are not able to solve it then we can refer to your explanation that would really really be helpful for beginners like me and all would really appreciate that effort of yours!!!! 🙏🙏🙏🙏

_shubhamr.sharma
Автор

First rule to be followed while solving these type of conditions is:
First of all we need to divide given expression into three parts i.e L|M|R
And then start evaluate each and expression.
Al last num variable initialised by A which is equivalent of 65.

satishsgm
Автор

Result is 65, start to solve from the inner bracket to the outer bracket, fixed inputs and take care of format specifier used during output, it will convert the result A into ASCII decimal 65 (%d is used for output)

bengalisareeshubstore
Автор

65 since sizeof var is 4or 8 according to processor which is True in boolean form and ascii value of A is 65 as we need to print in integer the value.

helloHima
Автор

O/p - ASCII Value of A= 65
Explained it perfectly man!!!!

jayap
Автор

#solution
#include <stdio.h>

int main()
{
int var=75, var2=56, num;
num=sizeof(var)?(var>23? ((var==75)?'A':0):0):0;
printf(" the num is :%d", num);


return 0;
}

output=65

AYUSHSINGH-pvpl
Автор

All other inner conditional expressions will be treated first. They return true. Then, the main operand, sizeof, returns true which implies 'A' will be returned.

Since %d specifier was used, the printf will print the decimal value of character A, which is 65.

otetumooluwaseun
Автор

Output will be ASCII value of 'A' ie. 65

abhijit