Using the tenary operator in C with 3 numbers - Printable Version +- QB64 Phoenix Edition (https://qb64phoenix.com/forum) +-- Forum: QB64 Rising (https://qb64phoenix.com/forum/forumdisplay.php?fid=1) +--- Forum: Code and Stuff (https://qb64phoenix.com/forum/forumdisplay.php?fid=3) +---- Forum: Utilities (https://qb64phoenix.com/forum/forumdisplay.php?fid=8) +---- Thread: Using the tenary operator in C with 3 numbers (/showthread.php?tid=2916) Pages:
1
2
|
Using the tenary operator in C with 3 numbers - Kernelpanic - 08-08-2024 The tenary operator was discussed here for some time ago, a bit complicated in Basic. It is quite useful for simple comparisons. The program uses the tenary operator in C with a triple comparison. It also works with four numbers, but that gets a bit confusing. If one only want to compare two numbers, simply enter 0 for the third number. -- Both files in the same directory. Code: (Select All)
Save the C program as btenaerDreifach.h Code: (Select All)
RE: Using the tenary operator in C with 3 numbers - Pete - 08-08-2024 For those of you who missed out watching reruns of Hogan's Heroes, the tenary operator is basically saying... if a then b otherwise c Which looks to me like the BASIC equivalent of our if/then/else statements. But then again, I could be channeling Sergent Schultz, in which case, "I know nothing, nothing!" Pete RE: Using the tenary operator in C with 3 numbers - Jack - 08-08-2024 Pete the difference is that you can assign the ternary expression to a variable, you can basically do the same with if then else, but sometimes you can simplify things by using the ternary expression, but I confess that the ternary operator looks weird unless you use it a lot RE: Using the tenary operator in C with 3 numbers - Pete - 08-08-2024 I look at it as shorthand... C=(A>B)?A:B; meaning: If A > B Then C = A Else C = B Pete RE: Using the tenary operator in C with 3 numbers - Kernelpanic - 08-08-2024 (08-08-2024, 08:53 PM)Pete Wrote: I kook at it as shorthand...I do not think so! Code: (Select All)
There c would have to be the largest number, right? RE: Using the tenary operator in C with 3 numbers - Pete - 08-09-2024 You can't assign c. Pete RE: Using the tenary operator in C with 3 numbers - SMcNeill - 08-09-2024 (08-09-2024, 01:05 AM)Pete Wrote: You can't assign c. Must be under this new, modern grading system. A, B, D, E, F ?? RE: Using the tenary operator in C with 3 numbers - Pete - 08-09-2024 This one was fun... Code: (Select All) Age = 30 So you don't assign beverage, it is determined by the assigned value of age. Pete RE: Using the tenary operator in C with 3 numbers - hsiangch_ong - 08-10-2024 https://en.wikipedia.org/wiki/Ternary spell it right. (not being a jerk. but i thought the word started with "ter" which got me to look it up.) https://en.wikipedia.org/wiki/Ternary_conditional_operator RE: Using the tenary operator in C with 3 numbers - Pete - 08-10-2024 (08-10-2024, 04:39 PM)hsiangch_ong Wrote: https://en.wikipedia.org/wiki/Ternary I think the Kernel was using the 8th instance of the function as in... I'm tenary the eighth I am Tenary the 8th I am I am I got called from the mainframe next door It's been booted seven times before And every call was a tenary, it couldn't call a driver or a cam I'm the eighth old function tenary Tenary the eighth I am Pete |