What does the modulus operator % do?

Q4. What does the modulus operator % do? What will be the result of 7.2%2.1 and 8%3?

Ans. The % operator finds the modulus of its operand relative to the second. That is, it produces the remainder of dividing the first by the second operand.

While using modulus operator both operands must be integer types.

So, 7.2%2.1 will produce an error “Illegal use of floating type”.

8%3 will produce 2 as result.

Binary Operators.

Q3. What are binary operators? Give examples of arithmetic binary operators.

Ans. Operators that act upon two operands are referred to as Binary Operators.

Examples of arithmetic binary operators are:

  • Addition operator +
  • Subtraction operator –
  • Multiplication operator *
  • Division operator /
  • Modulus operator %

How is ‘unary+’ operator different from ‘+’ operator? How is ‘unary-‘ operator different from ‘-‘ operator?

Q2. How is ‘unary+’ operator different from ‘+’ operator? How is ‘unary-‘ operator different from ‘-‘ operator?

Ans. The operator unary ‘+’ precedes an operand. The operand (the value on which the operator operates) of the unary + operator must have arithmetic or pointer type and the result is the value of the argument.

For example:

If a=5 then +a means 5.

The arithmetic binary operator + adds values of its operands and the result is the sum of the values of its two operands. Read More …

What is the function of operators? What are arithmetic operators?

Q1. What is the function of operators? What are arithmetic operators? Give their examples.

Ans. The operations being carried out on data, are represented by operators.

C++ provides operators for five basic arithmetic calculations: addition, subtraction, multiplication, division and remainder which are +,-,*,and %.

C program to ASCII code for digit and backspace.

Q48. Write a C program to

  • print ASCII code for a given digit.
  • print ASCII code for backspace.

(Hint: Store escape sequence for backspace in an integer variable).

Ans(i).

#include<stdio.h>  //for standard input and output

#include<conio.h>  //for clrscr()

 

//Main Function

void main()

{

int num;

clrscr();  //for clear screen

 

printf(“\n Enter a digit you want to print the ASCII value of: “); Read More …