'sizeof' Operator Concepts & Tricky Questions

Duration: 13 min

This video lesson is available to enrolled students.

Return to /learn/NIACL-AO-IT-SPECIALIST/c-concepts-mcqs/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. Quantitative Aptitude: Ratio and Proportion (Ratios), Data Interpretation, Mixture and Alligation, Permutation and Combination, Number System, Sequence and Series (Series), Speed Time and Distance, Speed Mathematics and Basic Mathematics, Algebra, Percentage, Profit and Loss, Simple Interest and Compound Interest, Powers and Exponents (Surds and Indices), Time and Work, Mensuration and Geometry, Partnership
  2. Reasoning Ability: Series (Number and Letter Series) (Numerical Relations and Reasoning), Coding Decoding, Data Sufficiency, Seating Arrangements, Deductive and Inductive Reasoning (Logical Deduction and Induction) (Prepositional Reasoning), Directions (Direction Test), Ranking, Order and Sequence, Syllogisms, Blood Relations, Puzzle Solving (Puzzles), Inequality, Machine Input-Output
  3. English Language: Vocabulary, Noun, Subject Verb Agreement (Verb Noun Agreement), Adjectives, 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), Sentence Construction, Pronoun, Preposition, Conjunction, Adverb, Verb, Modals, Articles, Determiner, Interjection
  4. General Awareness: Evolution of Indian Banking (Banking & Financial Awareness), GK- Current Affairs, Static General Knowledge, Indian Economy
  5. C Concepts + MCQs (IT Specialist): C Programming by Yash Sir, C Language Core
  6. Java (IT Specialist): Java
  7. Python (IT Specialist): Python for Placements by Yash Sir, Python Basics
  8. OOPs (IT Specialist): Object Oriented Programming (OOPS)
  9. DBMS (IT Specialist): 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
  10. SQL (IT Specialist): SQL
  11. Software Engineering (IT Specialist): Fundamentals of Software Engineering, Software Requirements and Quality Assurance, Software Design, Estimation and Metrics, Software Testing, Software Maintenance and Configuration Management
  12. Data Structure (IT Specialist): Introduction to DS, Array, Stack, Queue, Linked List, Tree, Graphs, Hashing
  13. Operating System (IT Specialist): 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
  14. Compiler Design (IT Specialist): Intro to Compilers, Lexical Analysis, Grammar & CFG, Syntax Analysis: Top-Down, Syntax Analysis: Bottom-Up, Semantic Analysis & SDT, Intermediate Code Gen, Code Optimization, Run Time Environment
  15. Computer Architecture (IT Specialist): Basics of COA, Floating Point Rep, Cache Memory Organization, Input Output Organisation, Pipelining, Instr Formats & Modes, Control Unit Design, Register Transfer and Microoperations, Multiprocessors, Programming the Basic Computer
  16. Data Communication & Networking (IT Specialist): 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
  17. Descriptive Test (Main Exam): English Writing Ability
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…