Skip to main content Accessibility help
Internet Explorer 11 is being discontinued by Microsoft in August 2021. If you have difficulties viewing the site on Internet Explorer 11 we recommend using a different browser such as Microsoft Edge, Google Chrome, Apple Safari or Mozilla Firefox.

I: Common Questions and Answers

I: Common Questions and Answers

pp. 607-629

Authors

, Techno India Hooghly, West Bengal, , Techno India College of Technology, West Bengal
  • Add bookmark
  • Cite
  • Share

Extract

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.

About the book

Access options

Review the options below to login to check your access.

Purchase options

Paperback
US$105.00

Have an access code?

To redeem an access code, please log in with your personal login.

If you believe you should have access to this content, please contact your institutional librarian or consult our FAQ page for further information about accessing our content.

Also available to purchase from these educational ebook suppliers