Q10 - Precedence and Associativity

Duration: 3 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-q10-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 presents a coding problem involving the C++ modulus operator with a negative divisor. The question asks for the value of the expression `int x = 4 + 2 % (-8);`. The instructor first analyzes the expression by applying the order of operations, noting that the modulus operation `%` has higher precedence than addition. He then explains the mathematical rule for the sign of the modulus result, which is the same as the sign of the dividend (the number being divided). In this case, 2 is the dividend, so `2 % (-8)` evaluates to 2. The final result is `4 + 2`, which is 6. To confirm this, the instructor switches to a C++ online compiler, types the code, and runs it, showing the output as 6, thereby validating the theoretical calculation.

Chapters

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

    The video begins with a question displayed on a whiteboard: `Q. The expression, int x = 4 + 2 % (-8); evaluates to:` with four options: (1) -6, (2) 6, (3) 4, (4) None of these. The instructor, Yash Jain, starts to solve the problem by writing the expression `4 + 2 % (-8)` on the board. He then performs a long division of 2 by -8, writing `8)2` and showing that 8 goes into 2 zero times with a remainder of 2. He concludes that `2 % (-8)` is 2. He then adds this to 4, writing `4 + 2` and getting the result 6. He circles the number 6 on the board, indicating it as the answer. He also writes a general rule: `a % (-b) = a % b` and `a % b` where `a < b`. He then writes `PUMA's REBL TAC` and `1234` with a circle around the number 3, possibly as a mnemonic or a joke.

  2. 2:00 – 2:48 02:00-02:48

    The instructor transitions from the whiteboard to a live coding environment, an online C++ compiler. He types the code `#include <iostream> using namespace std; int main() { int x = 4 + 2 % (-8); cout << x; }`. He then clicks the 'Run' button. The output console displays the result as `6`. This practical demonstration confirms the theoretical calculation from the whiteboard, showing that the expression evaluates to 6. The instructor's final answer is 6, which corresponds to option (2).

The video effectively combines theoretical explanation with practical verification. It first presents a common point of confusion in programming: the behavior of the modulus operator with negative numbers. The instructor uses a step-by-step mathematical approach to demonstrate that the sign of the result is determined by the dividend, not the divisor. This is a crucial concept for understanding the C++ modulus operator. The lesson is then solidified by a live coding demonstration, which provides empirical evidence for the theoretical result, reinforcing the learning objective and ensuring the student understands both the 'why' and the 'how' of the operation.

Loading lesson…