Skip to the content
onlineexamguide
  • Home
  • Courses
  • Engg. Interview
    • Placement Papers
    • Electrical Engineering
    • Mechanical Engineering
    • Automobile Engineering
    • Civil Engineering
    • Computer Science Engineering
    • Chemical Engineering
    • CS & IT Engg.
      • C programming Tests
      • C++ programming Tests
      • Java Programming Tests
  • Online Exam
    • NTA UGC NET Exam
    • SSC Examination quiz
    • TET Examination Quiz
    • Banking Exam
    • Aptitude Tests
    • Computer Knowledge Tests
    • Logical Reasoning Tests
    • English Language Tests
    • Staff Nurse Exams
    • General Knowledge Tests
    • Networking Tests
  • Ghatna Chakra
  • Register
    • Instructor Registration
    • Student Registration
    • About us
    • Privacy Policy
  • Cart
  • User Login
  • Home
  • Courses
  • Engg. Interview
    • Placement Papers
    • Electrical Engineering
    • Mechanical Engineering
    • Automobile Engineering
    • Civil Engineering
    • Computer Science Engineering
    • Chemical Engineering
    • CS & IT Engg.
      • C programming Tests
      • C++ programming Tests
      • Java Programming Tests
  • Online Exam
    • NTA UGC NET Exam
    • SSC Examination quiz
    • TET Examination Quiz
    • Banking Exam
    • Aptitude Tests
    • Computer Knowledge Tests
    • Logical Reasoning Tests
    • English Language Tests
    • Staff Nurse Exams
    • General Knowledge Tests
    • Networking Tests
  • Ghatna Chakra
  • Register
    • Instructor Registration
    • Student Registration
    • About us
    • Privacy Policy
  • Cart
  • User Login

C Programming Arithmetic Operator

Arithmetic Operators

Learn C Programming Arithmetic Operator MCQ Questions and Answers on Basics to attend job placement exams, interview questions, college viva and Lab Tests

C language comes with Arithmetic Operators like Plus, Minus, Multiplication, Division and Modulo Division. One more operator ‘=’, also called Assignment operator is also present.

C Programming Arithmetic Operators are used to work with integers and real numbers.

Study C basics and keywords before this tutorial.

Arithmetic Operator

SNOOperatorDescription
1+Addition Operator
2–Subtraction Operator
3*Multiplication Operator
4/Multiplication Operator
5%Modulo Division Operator

C Programming Arithmetic Operator

Example 1:

int main()
{
  int a=5, b=10;
  int c;
  // = is Assignment operator
  c = a + b;
  printf("%d ", c);
  
  c = a - b;
  printf("%d ", c);
  
  c = a*b;
  printf("%d ", c);
  
  c = b/a;
  printf("%d ",c);

  c = a%b; //modulo division or remainder operator
  printf("%d", c);
  
  return 0;
}
//output:  15  -5  50  2  5

Assignment Operator allows only right side value to be assigned to the left side variable. In the above program, left side variable ‘C’ gets the value of right side operation like addition, subtraction etc.

Note: Modulo division operator works only with whole numbers like integers.

Note: Arithmetic operators can also be applied on char variables as characters are converted to their respective ASCII codes before arithmetic operation.

Integer and Float Conversions

When you are working with integers and float (Real) numbers, some number conversions are applied.

  1. Result of int and int is integer only. Use %d format specifier. Use an int variable to hold data.
  2. Result of float and float is float only. Use %f format specifier. Use a float variable to hold data.
  3. Result of int and float is float only. Use %f format specifier. Use a float variable to hold data.
  4. If you use %d instead of %f, precision data will be lost.
  5. If you are working with long, double and long double data types, result of an arithmetic operation contains higher data type value. For example, arithmetic operation with short and int is always int.

Example 1:

int main()
{
  int a=5, b=10;
  float c = 12.5f, d = 10.5f;
  
  //int + int
  printf("%d, ", a+b);
  
  //float + float
  printf("%f, ", c+d);
  
  //int + float
  printf("%f, ", a + c);
  
  //int + float
  printf("%d", a + c);
  //%d truncates extra data i.e precision
  
  return 0;
}
//output: 15, 23, 17.500000, 17

Example 2:

SNOArithmetic OperationResult
1.9/24
2.9/2.04.5
3.9.0/24.5
4.9.0/2.04.5
5.2/90
6.2/9.00.22
7.2.0/90.22
8. 2.0/9.00.22

Note: To avoid losing of precision data with division operator, multiply the numerator or denominator with 1.0f or 1.0 double value. Use parantheses ( ) operator to group all numerator or denominator expressions.

int main()
{
  int a=10, b=4;
  float c = (1.0f * a) / b;
  //multiply with 1.0f or 1.0
  printf("%f", c);
    
  return 0;
}
//output: 2.500000

C Operator Precedence or Priority or Hierarchy

Each operator in C has a precedence or priority or hierarchy. Operator precedence is useful to evaluate arithmetic expressions with operators of different priority. Operator priority decides which operator and operands should be evaluated first.

Note: Constants on the left and right side of operator are called Operands.

Example 1:

int main()
{
  int a=2, b=3, c=8;
  int d=0;
  d = a + b * c;
  printf("%d", d);
  
  return 9;
}
//output:
// 2 + (3*8)
// 2 + 24
// 26 is the output
//'*' operator has higher priority
// wrong = (a+b)*c

C Operator Precedence Chart

PriorityOperatorDescription
1st*, /, %Multiplication, Division, Modulo Division
2nd+, –Addition, Subtraction
3rd=Assignment

Example 2:

int main()
{
  float abc = 5 + 10 / 2 * 5 - 2 % 5;
  printf("Result=%f", abc);
  
  return 0;
}
//Evaluation steps
//10 / 2 * 5 left to right processing
//5 + 25 - 2 left to right processing
// START
// 5 + (10 / 2) * 5 - 2 % 5
// 5 + 5 * 5 - 2 % 5
// 5 + 25 - 2 % 5
// 5 + 25 - 2
// 30 - 2
// 28
//END

C Operator Associativity

C operator associativity deals with the problem of associating an operand to either left operator or right operator. When two equal priority operators are encountered in an expression, this Operator associativity is used to solve deadlock. Usually arithmetic operators follow Left to Right Associativity. Equals to ‘=’ operator follows Right to Left Associativity.

Example 1:

int d = 3 + 4 + 5;

Now as per Left to Associativity of arithmetic operators, 4 belongs to the left side + or first + operator. So the expression becomes (3+4) + 5. Next, the result of expression is added to 5 like (7)+5.

Now as per Right to Left Associativity of Equals to Operator, right side value is assigned to left side variable. So the variable d now holds a value of 12.

Example 2: 

float fd = 3 + 12 / 5;

In the code above, there are two operators + and /. As Division / operator has higher priority, operand 12 is associated with /.  instead of + on the left side. So 12/5 evaluates to 2. fd = 3 + 2 = 5 now.

learn C Programming Syntax Basics in this multipart tutorial which are useful for students in the last minute before exam. C Programming Language was invented by Dennis Ritchie in Bell Laboratories. Now Nokia owns Bell Laboratories and experiments are still going on.

C Programming Syntax Basics Part 1

We shall learn about basic structure of a C Program and predefined Keywords in this C Programming Syntax Basics Tutorial Part 1. You can set up a Turbo C Compiler on your Windows Machine easily.

Online Tests on C Basics

1C Programming Basics 1
2C Programming Basics 2

Structure of a C Program

Every C program contains a function or method called main(). All functions end with Round Brackets or Paranthesis ( ). Inside Paratheses, arguments can be received or passed. Code of a Function is surrounded by Curly Brackets or Braces { }.

#include <stdio.h>
void main()
{
  /*This is a multi-line comment.
     It is not compiled or checked for Syntax*/
  printf("Hello C..");
}

Output

Hello C..

Observations

  1. VOID is a return type. VOID means nothing is being returned.
  2. main() { } is a compulsory function in any C Program.
  3. void and main should be typed in lowercase completely.
  4. / symbol is called Forward Slash or simply Slash.
  5. * symbol is called STAR.
  6. /* */ is a multiline comment. Comments are useful for analysing code logic flow in very big projects. Comments make others easily understand your program or project.
  7. printf() is a function which is passing one argument “Helllo C”.
  8. “Hello C” is a string literal here.
  9. Code statements or lines end with Semicolon ;
  10. Putting a return type before a function name is not mandatory in a C Compiler. If you use a C++ Compiler to compile c programs, you must specify a return type.
  11. #include includes an already written header file stdio.h which contains code for printf function. Without predefined functions, life becomes difficult to write everything every time on our own. Also the code without including files becomes clumsy to maintain and understand.

Keywords in C Language

There are a total of 32 keywords in C Language which can not be used for the names of variables and functions. Find the C Programming Keyword list below. Students need to remember these keywords just like that to attempt questions asked in their exams.

KeywordMeaning
auto Defines local life time for a variable
break Breaks a current loop in general
case Defines branch control point
char Basic data type, character literal
const Defines a Constant, unmodified variable
continue control goes to the loop beginning
default control point used in switch construct in general
do do while loop
double Floating point data type bigger than float type
else Usually followed by if construct. If conditon fails, branch to else block
enum Used to define a  group of int constants like array
extern Used to define a variable or function with type and the definition may exist some where 
float Floating point data type
for For Loop
goto Transfers execution control to defined Label
if A conditional statement
int Basic integer data type
long Integer data type bigger than int
register Tells to store the variable in RAM register
returnends execution immediately
short Type Modifier
signed Type Modifier
sizeofused to get the size of a variable. Eg. sizeof(integerType)
staticused to create a variable with broad scope
struct Used to define a custom data type kind of thing
switch switch branch control
typedef used to create new type
unionused in grouping of variables of same type
unsignedModifiere used to increase positive max value
void empty data type or return type
volatileUsed to create a variable with a value changed by any external process
whilewhile loop with a condition

Arithmetic Operator interview MCQ

[WpProQuiz 25]

Write a comment Cancel reply

You must be logged in to post a comment.

Recent Posts

  • Atal Bihari Vajpayee | श्री अटल बिहारी वाजपेयी जीवन परिचय
  • सम्राट अशोक का जीवन परिचय (Emperor Ashoka)
  • Prithviraj Chauhan
  • बाल गंगाधर तिलक
  • स्वामी दयानंद सरस्वती
  • UPPSC Mines Inspector Recruitment 2022 Notification Out
  • AIIMS Delhi JR Vacancy 2022 [194 Post] Notification and Apply Online
  • भीमराव अम्बेडकर
  • डॉक्टर राजेंद्र प्रसाद का जीवन परिचय
  • श्रीनिवास रामानुजन का जीवन परिचय
  • Amnesty International day
  • World Economic Forum
  • UPSSSC VDO Syllabus and Exam Pattern 2022
  • RBI Officer Grade B Recruitment 2022
  • UKMSSB Assistant Professor Recruitment 2022 Apply Now 339 Post

About us

Free online test to practice for Competitive exams , Online Exam, Entrance and Interview. Learn and Practice online test for Free and Prepare for your exam online with us

Select Language

Follow us

Search

Learn and Earn

Register as Instructor - Create and sell online courses and coaching services with the best online platform onlineexamguide.com . Build a course, build a brand, earn money

Copyright © 2022 onlineexamguide.com - All Rights Reserved.
error: Content is protected !!

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.