How Void Pointer behave differently in C & C++

Duration: 10 min

This video lesson is available to enrolled students.

Return to /learn/COCUBES-PREPARATION/coding/programming-in-c/c-mcqs-by-yash-sir/asset-how-void-pointer-behave-differently-in-c-c after enrolling

Inside: a video lesson and guided study material.

Module outline

  1. Quantitative Aptitude: Number System, Divisibility Rules, HCF LCM, Percentage, Ratio and Proportion (Ratios), Average, Profit and Loss, Simple Interest and Compound Interest, Mixture and Alligation, Partnership, Age Problems, Time and Work, Pipe and Cistern, Speed Time and Distance, Algebra, Arithmetic, Data Interpretation, Sequence and Series (Series), Logarithm, Powers and Exponents (Surds and Indices), Permutation and Combination, Probability, Speed Mathematics and Basic Mathematics, Trigonometry
  2. Logical Reasoning: Coding Decoding, Blood Relations, Directions (Direction Test), Ranking, Order and Sequence, Seating Arrangements, Puzzle Solving (Puzzles), Data Arrangement, Syllogisms, Inequality, Data Sufficiency, Deductive and Inductive Reasoning (Logical Deduction and Induction) (Prepositional Reasoning), Series (Number and Letter Series) (Numerical Relations and Reasoning), Venn Diagram, Logical Sequence Of Words, Calendar, Clock, Cubes & Dices, Non Verbal Reasoning (Spatial Aptitude) (Spatial Reasoning) (Visual Reasoning)
  3. Verbal Ability: Noun, Pronoun, Adjectives, Verb, Adverb, Tenses, Subject Verb Agreement (Verb Noun Agreement), Articles, Preposition, Conjunction, Modals, Determiner, Vocabulary, 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), Active Passive Voice (Voice), Direct and Indirect Speech, Sentence Construction
  4. Data Structures (Domain Test): Introduction to DS, Array, Stack, Queue, Linked List, Tree, Graphs, Hashing
  5. Algorithms (Domain Test):
  6. OOPs (Domain Test): Object Oriented Programming (OOPS)
  7. DBMS (Domain Test): 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
  8. SQL (Domain Test): SQL
  9. Operating Systems (Domain Test): 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
  10. Computer Networks (Domain Test): 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, Cloud Computing and IoT, Cyber and Info Security
  11. Coding: Coding Questions by Yash Sir, C Programming by Yash Sir, Programming in C++, Java, Python for Placements by Yash Sir
  12. Written English Test: English Writing Ability
  13. Psychometric Test: Behavioral Assessment (Behavioral Competency Profiling) (Psychometric Test)
AI summary & chapters

AI Summary

An AI-generated summary of this video lecture.

This educational video, presented by Yash Jain from Knowledge Gate Eduventures, is a comprehensive tutorial on the application of void pointers in C and C++. The lecture begins with an introduction to the topic, using a title slide that displays the C and C++ logos and the text 'Application of Void pointer'. The instructor then transitions to a code-based explanation, presenting two code snippets side-by-side: one in C and one in C++. The core of the lesson focuses on the incompatibility between `void *` and `char *` pointers. The instructor demonstrates that in C++, a direct assignment like `char *ptr2 = ptr1;` where `ptr1` is a `void *` pointer will result in a compilation error due to the strict type checking. This is contrasted with C, where such a conversion is allowed implicitly. The video provides a practical demonstration using an online C++ compiler, showing the exact error message: 'error: invalid conversion from 'void*' to 'char*' [-fpermissive]'. To resolve this, the instructor shows the correct method: explicit type casting, writing `ptr2 = (char*)ptr1;`. The video concludes with a 'Thanks' slide, providing contact information for the course provider.

Chapters

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

    The video opens with a title slide for a programming lecture. The slide features a dark background with green and white C++ code floating around. The main title is 'C++ PROGRAMMING' in large white letters, with 'By YASH JAIN' in the top right corner. The slide also includes a graphic of a computer monitor with the C and C++ logos and the text 'Application of Void pointer'. The instructor, Yash Jain, is visible in a small window in the bottom right corner. The slide also contains a copyright notice for 'KNOWLEDGE GATE EDUVENTURES' and a call to action to download the KG app or visit their website.

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

    The video transitions to a code demonstration. The screen is split into two sections, each showing a C++ code snippet. The left snippet is labeled 'C' and the right is labeled 'C++'. Both snippets contain the same code: `#include <stdio.h>`, `int main()`, `{`, `void *ptr1;`, `char *ptr2;`, `ptr2 = ptr1;`, `return 0;`, `}`. The instructor explains that in C++, this code will not compile due to a type mismatch. He then writes on the screen, adding `char *ptr;` and `int *ptr;` to illustrate the concept of type casting. The instructor's voiceover explains that a `void *` pointer can point to any data type, but it cannot be directly assigned to a pointer of a specific type like `char *` without an explicit cast.

  3. 5:00 – 9:45 05:00-09:45

    The instructor continues the demonstration, focusing on the C++ code snippet. He highlights the line `ptr2 = ptr1;` and explains that this is an invalid conversion. He then shows the correct way to perform the conversion by adding an explicit cast: `ptr2 = (char*)ptr1;`. The video then cuts to a screen recording of an online C++ compiler, where the instructor types the code and runs it, showing the compilation error: 'error: invalid conversion from 'void*' to 'char*' [-fpermissive]'. He then adds the cast, and the code compiles successfully. The video ends with a 'Thanks' slide, providing contact information for the course provider, including a Telegram group and an email address.

The video provides a clear and practical lesson on a fundamental concept in C++ programming: the use of void pointers. It effectively contrasts the behavior of C and C++ when dealing with type conversions, highlighting the stricter type safety in C++. The instructor uses a combination of visual aids, code examples, and a live coding demonstration to explain the problem and its solution. The key takeaway is that while a `void *` pointer can store the address of any data type, it must be explicitly cast to a specific pointer type before it can be used to access the data, a crucial rule for writing safe and portable C++ code.

Loading lesson…