Q7 - Precedence and Associativity

Duration: 2 min

This video lesson is available to enrolled students.

Return to /learn/TCS-NQT-PREPARATION/advanced-coding/programming-in-c/c-by-yash-sir/asset-q7-precedence-and-associativity after enrolling

Inside: a video lesson and guided study material.

Module outline

  1. TCS One Shot Free Videos & Notes: TCS Preparation
  2. Numerical Ability (Foundation Section): Ratio and Proportion (Ratios), Divisibility Rules, Data Interpretation, Mixture and Alligation, Permutation and Combination, Logarithm, Number System, HCF LCM, Sequence and Series (Series), Speed Time and Distance, Percentage, Average, Powers and Exponents (Surds and Indices), Algebra, Probability, Profit and Loss, Simple Interest and Compound Interest, Time and Work, Pipe and Cistern, Mensuration and Geometry, Mental Ability, Age Problems, Statistics, Arithmetic, Partnership, Speed Mathematics and Basic Mathematics
  3. Reasoning Ability (Foundation Section): Series (Number and Letter Series) (Numerical Relations and Reasoning), Coding Decoding, Data Sufficiency, Non Verbal Reasoning (Spatial Aptitude) (Spatial Reasoning) (Visual Reasoning), Syllogisms, Deductive and Inductive Reasoning (Logical Deduction and Induction) (Prepositional Reasoning), Seating Arrangements, Blood Relations, Directions (Direction Test), Analytical Reasoning (Counting Figures Reasoning), Puzzle Solving (Puzzles), Calendar, Clock, Cubes & Dices, Selection Decision Table (Decision Making), Crypt Arithmetic, Venn Diagram, Data Arrangement, Inequality, Analogy, Ranking, Order and Sequence, Logical Sequence Of Words
  4. New Pattern-Verbal Ability (Foundation Section): Sentence Completion (Fill in the blanks), English Writing Ability
  5. Old Pattern-Verbal Ability (Foundation Section): Vocabulary, Noun, Subject Verb Agreement (Verb Noun Agreement), Adjectives, Tenses, Pronoun, Preposition, Articles, Direct and Indirect Speech, Conjunction, Modals, Sentence Re-arrangements (Para Jumbles) (Narrative Sequencing), Sentence Correction (Error Correction), Comprehension / Reading Comprehension / Unseen Passages (Critical Reasoning) (Paragraph Questions), Verbal Analogy (Word Based Analogy), Active Passive Voice (Voice), Determiner, Facts, Inference and Judgements, Adverb, Cloze Test (Cloze Passage), Sentence Construction, Verb
  6. Advanced Quantitative Ability: TCS NQT Advanced Quantitative Ability
  7. Advanced Reasoning Ability: TCS NQT Advanced Reasoning Ability
  8. Advanced Coding: Coding Questions by Yash Sir, C Programming by Yash Sir, Python for Placements by Yash Sir, DSA using Python, Object Oriented Programming (OOPS), Programming in C++, Java
  9. TCS Full Length Mock Test:
  10. TCS Interview & Resume Prep: MR & HR Interview Preparation, TCS Interview Preparation, Mock Interview, Interview Recordings, Resume Preparation, Resume Review
  11. Mega Test:
  12. Grand Test:
AI summary & chapters

AI Summary

An AI-generated summary of this video lecture.

The video is a coding tutorial that demonstrates the evaluation of a complex arithmetic expression in C++ by applying the rules of operator precedence. The instructor, Yash Jain, presents a C++ program with a single line of code: `int i = 2 * 3 / 4 + 4 / 4 + 8 - 2 + 5 / 8;`. He then manually breaks down the calculation step-by-step on a whiteboard, starting with the multiplication and division operations from left to right, which are performed first. The expression is simplified to `6 / 4 + 4 / 4 + 8 - 2 + 5 / 8`. He continues by evaluating the divisions, resulting in `1 + 1 + 8 - 2 + 0`, and then performs the addition and subtraction from left to right, leading to the final result of 8. The video concludes with a screen recording of the OnlineGDB compiler, where the program is executed, and the output `8` is displayed, confirming the manual calculation.

Chapters

  1. 0:00 – 2:00 00:00-02:00

    The video begins with a C++ code snippet displayed on a dark background, which includes the standard library and namespace. The main function contains the expression `int i = 2 * 3 / 4 + 4 / 4 + 8 - 2 + 5 / 8;`. The instructor, Yash Jain, starts to solve this expression by first identifying the operators and their precedence. He explains that multiplication and division have higher precedence than addition and subtraction and are evaluated from left to right. He begins the calculation by performing the multiplication `2 * 3`, which equals 6, and then the division `6 / 4`, which results in 1 (integer division). He then moves to the next part of the expression, `4 / 4`, which equals 1. The expression is now simplified to `1 + 1 + 8 - 2 + 5 / 8`. He continues by evaluating `5 / 8`, which results in 0. The expression is now `1 + 1 + 8 - 2 + 0`. He then performs the addition and subtraction from left to right, calculating `1 + 1` to get 2, then `2 + 8` to get 10, then `10 - 2` to get 8, and finally `8 + 0` to get 8. The final result is 8.

  2. 2:00 – 2:24 02:00-02:24

    The video transitions to a screen recording of the OnlineGDB online compiler. The same C++ code is shown in the editor. The instructor clicks the 'Run' button, and the program executes. The output window at the bottom displays the message `Program finished with exit code 0` and the result `8`, confirming the manual calculation. The instructor points to the output, reinforcing that the final value of the variable `i` is indeed 8. The video ends with the compiler window still open, showing the successful execution of the program.

The video provides a clear, step-by-step demonstration of how to evaluate a complex arithmetic expression in C++ by strictly following the rules of operator precedence and associativity. It effectively bridges the gap between theoretical knowledge and practical application by first showing the manual calculation on a whiteboard and then verifying the result using a live compiler. This approach reinforces the concept that integer division truncates the decimal part, a crucial detail for accurate results in C++ programming.

Loading lesson…