'sizeof' Operator Concepts & Tricky Questions

Duration: 13 min

This video lesson is available to enrolled students.

Return to /learn/COGNIZANT-PREPARATION/technical-assessment/c-programming-by-yash-sir/c-language-mcqs/asset-sizeof-operator-concepts-tricky-questions-13222 after enrolling

Inside: a video lesson and guided study material.

Module outline

  1. Communication Round: Vocabulary, Subject Verb Agreement (Verb Noun Agreement), Tenses, Comprehension / Reading Comprehension / Unseen Passages (Critical Reasoning) (Paragraph Questions), Cloze Test (Cloze Passage), Sentence Correction (Error Correction), Sentence Completion (Fill in the blanks), Sentence Re-arrangements (Para Jumbles) (Narrative Sequencing), Direct and Indirect Speech, Active Passive Voice (Voice), Verbal Analogy (Word Based Analogy), Articles, Preposition, Conjunction, Sentence Construction, English Writing Ability, Communication Assessment
  2. Quantitative Aptitude: Ratio and Proportion (Ratios), Divisibility Rules, Data Interpretation, Mixture and Alligation, Permutation and Combination, Logarithm, Number System, HCF LCM, Speed Time and Distance, Percentage, Average, Powers and Exponents (Surds and Indices), Time and Work, Mensuration and Geometry, Age Problems, Pipe and Cistern, Probability, Profit and Loss, Simple Interest and Compound Interest, Algebra
  3. Analytical and Logical Reasoning: Series (Number and Letter Series) (Numerical Relations and Reasoning), Coding Decoding, Data Sufficiency, Non Verbal Reasoning (Spatial Aptitude) (Spatial Reasoning) (Visual Reasoning), Directions (Direction Test), Ranking, Order and Sequence, Deductive and Inductive Reasoning (Logical Deduction and Induction) (Prepositional Reasoning), Selection Decision Table (Decision Making), Logical Sequence Of Words, Puzzle Solving (Puzzles), Syllogisms, Seating Arrangements, Calendar, Clock, Blood Relations, Cubes & Dices, Venn Diagram, Analytical Reasoning (Counting Figures Reasoning)
  4. Cognizant Gaming Aptitude: Gamified / Game Based Aptitude
  5. Java (Cluster 1): Java
  6. ANSI SQL MySQL (Cluster 1,2,3): SQL
  7. HTML, CSS, JavaScript (Cluster 1,3): HTML, CSS, JavaScript
  8. Python (Cluster 2): Python for Placements by Yash Sir
  9. Cloud Fundamentals (Cluster 2): Emerging Tech Trends
  10. C# (Cluster 3): C#
  11. OOPs: Object Oriented Programming (OOPS)
  12. Technical Assessment (Coding): Coding Questions by Yash Sir, C Programming by Yash Sir, Programming in C++, Pseudo Codes
  13. Data Structures: Introduction to DS, Array, Stack, Queue, Linked List, Tree, Graphs, Hashing
  14. DBMS: Basics of DBMS, ER Diagram, Relational Model & Functional Dependencies, Keys & Integrity Constraints, Normalization (1NF - BCNF), Decomposition Properties & 4NF, File Organization & Indexing, Relational Algebra, Relational Calculus, Transaction Management, Concurrency Control, Database Recovery, ORDBMS, Database Security & Authorization, Query Processing & Optimization, Enhanced Data Models, Data Warehousing & Mining, Big Data Systems, NoSQL
  15. Operating Systems: Introduction to OS, Process Management, CPU Scheduling, Process Synchronization, Deadlock, Threads & Process Creation, Memory Management, Virtual Memory, Disc Scheduling, File Management, Windows OS, Linux OS, Security, Distributed Systems, Virtual Machines
  16. Computer Networks: Introduction to CN, Data Communication, DLL: Access Control, DLL: Flow Control, DLL: Error Control, DLL: Framing, Data Link Layer - Ethernet, Net Layer: IPv4 & Proto, Net Layer: IP Addressing, Net Layer:Routing Protocol, Transport Layer Services, TL: Congestion & UDP, Application Layer, Hardware basics, Network Security, Mobile Technology, Cloud Computing and IoT, Cyber and Info Security
AI summary & chapters

AI Summary

An AI-generated summary of this video lecture.

This educational video is a lecture on C programming, specifically focusing on multiple-choice questions (MCQs) related to the `sizeof` operator and the `printf` function. The instructor, Yash Jain, presents a series of code snippets on a digital blackboard, explaining the output of each program. The first problem involves the `sizeof` operator applied to a post-increment expression, `sizeof(i++)`, which evaluates to the size of an integer (4 bytes) because the expression is evaluated in a context where its value is not used, thus the increment does not occur. The second problem demonstrates the `sizeof` operator on a compound assignment expression, `sizeof(k /= i + j)`, where the expression `k /= i + j` is evaluated as `15 / (5 + 10)`, resulting in `1`, and the `sizeof` operator returns the size of the result, which is 4 bytes. The third problem is a classic trick question where `sizeof(printf("Accenture"))` is evaluated. The `printf` function returns the number of characters printed (9), and `sizeof` returns the size of that integer (4 bytes), so the output is `4Accenture`. The video uses a combination of on-screen code, handwritten annotations, and a live coding environment to explain the concepts, emphasizing the importance of understanding operator precedence and evaluation order.

Chapters

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

    The video opens with a title slide for a C Programming MCQs lecture by Yash Jain. The instructor then presents the first problem, a C code snippet with the code: `#include <stdio.h> int main() { int i = 12; int j = sizeof(i++); printf("%d %d", i, j); return 0; }`. The question asks for the output, assuming an integer size of 4 bytes. The instructor begins to explain that the `sizeof` operator is a compile-time operator and that the expression `i++` is evaluated in a context where its value is not used, so the increment does not take place, and `sizeof(i++)` returns the size of an integer, which is 4 bytes.

  2. 2:00 – 5:00 02:00-05:00

    The instructor moves to the second problem, displaying the code: `#include <stdio.h> int main() { int i = 5, j = 10, k = 15; printf("%d ", sizeof(k /= i + j)); printf("%d", k); return 0; }`. He explains that the expression `k /= i + j` is a compound assignment. The `sizeof` operator is applied to this expression. The expression is evaluated as `k = k / (i + j)`, which is `15 / (5 + 10)`, resulting in `1`. The `sizeof` operator then returns the size of the result of the expression, which is an integer, so the output is `4`. The second `printf` prints the value of `k`, which is now `1`.

  3. 5:00 – 10:00 05:00-10:00

    The instructor presents the third problem: `#include <stdio.h> int main() { printf("%d ", sizeof(printf("Accenture"))); return 0; }`. He explains that `printf("Accenture")` returns the number of characters printed, which is 9. The `sizeof` operator is then applied to this return value, which is an integer. Therefore, `sizeof(printf("Accenture"))` evaluates to the size of an integer, which is 4 bytes. The output of the program is `4Accenture`. The instructor uses a live coding environment to verify the output, showing that the program prints `4Accenture`.

  4. 10:00 – 12:40 10:00-12:40

    The video concludes with a final summary of the key concepts. The instructor reiterates that the `sizeof` operator returns the size of the type of its operand. For the first problem, `sizeof(i++)` returns 4 because the expression is not evaluated for its value. For the second, `sizeof(k /= i + j)` returns 4 because the expression evaluates to an integer. For the third, `sizeof(printf("Accenture"))` returns 4 because `printf` returns an integer. The instructor emphasizes that understanding the evaluation order and the context in which operators are used is crucial for solving such problems. The video ends with a brief appearance of the instructor in front of a screen with the Unacademy logo.

The video provides a comprehensive analysis of C programming concepts, focusing on the `sizeof` operator and its interaction with other operators. The core learning progression is built around three distinct problems that progressively increase in complexity. The first problem teaches that `sizeof` is a compile-time operator and that expressions within it are not evaluated for their side effects if their value is not needed. The second problem demonstrates that `sizeof` applied to a compound assignment expression evaluates the expression and returns the size of the result. The third problem is a classic trick question that tests the understanding of function return values and the `sizeof` operator. The synthesis of these examples highlights the importance of operator precedence, evaluation order, and the distinction between compile-time and run-time operations in C programming.

Loading lesson…