Published online by Cambridge University Press: 17 July 2025
What is the difference between Compiler and Interpreter? What is ternary operator?
Ans: Ternary operator is an operator which has three operands. In C, there is a ternary operator named conditional operator or ‘ ? : ‘ operator. The general form of conditional operator is:
Expression 1 ? Expression 2 : Expression 3
First expression1 is evaluated. If the expression1 is true, then expression2 is evaluated otherwise expression3 is evaluated.
The above program prints the maximum between two inputted numbers.
Ternary operator can also be nested.
For example,
The above statement finds the maximum between three inputted numbers. Here, after evaluation of expression1, it faces another conditional operator at the position of expression2 or expression3.
What are the functions of the typecast operator and size of operator?
Ans: Typecast operator: The typecast operator is used to convert the value of any data type to the specified data type explicitly. The typecast operator is written as (data type) expression
For Example, int a = 5, b=2;
float c;
c = a/b;
In the above example, though c is a float variable, it will contain 2 as a and b both are integer variable and operation on both integers produce integer. So, to get the exact result, typecast operator is required. And we have to write,
Now, the value of a will be first converted to float. Then division will be performed. So, we get the exact result, i.e., 2.5.
To save this book to your Kindle, first ensure no-reply@cambridge-org.demo.remotlog.com is added to your Approved Personal Document E-mail List under your Personal Document Settings on the Manage Your Content and Devices page of your Amazon account. Then enter the ‘name’ part of your Kindle email address below. Find out more about saving to your Kindle.
Note you can select to save to either the @free.kindle.com or @kindle.com variations. ‘@free.kindle.com’ emails are free but can only be saved to your device when it is connected to wi-fi. ‘@kindle.com’ emails can be delivered even when you are not connected to wi-fi, but note that service fees apply.
Find out more about the Kindle Personal Document Service.
To save content items to your account, please confirm that you agree to abide by our usage policies. If this is the first time you use this feature, you will be asked to authorise Cambridge Core to connect with your account. Find out more about saving content to Dropbox.
To save content items to your account, please confirm that you agree to abide by our usage policies. If this is the first time you use this feature, you will be asked to authorise Cambridge Core to connect with your account. Find out more about saving content to Google Drive.