Bit Fields In C & C++

  Рет қаралды 21,890

CppNuts

CppNuts

6 жыл бұрын

JOIN ME
-----
KZfaq 🎬 / @cppnuts
Patreon 🚀 / cppnuts
COMPLETE PLAYLIST
------------
C++ Tutorial For Beginners: • Introduction To C++
STL (Standard Template Library): • STL In C++
ThreadIng In C++: • Multithreading In C++
Data Structures: • Data Structure
Algorithms: • Binary Search
Design Patterns: • Factory Design Pattern...
Smart Pointers: • Smart Pointer In C++
C++14: • Digit Separator In C++
C++17: • std string_view in C++...
C++ All Type Casts: • static_cast In C++
INTERVIEW PLAYLIST
------------
C++ Interview Q&A: • Structural Padding & P...
C++ Interview Q&A For Experienced: • How delete[] Knows How...
Linked List Interview Questions: • Find Kth Node From Bac...
BST Interview Questions: • Search Element In Bina...
Array Interview Questions: • Reverse An Array
String Interview Questions: • Check String Is Palind...
Bit Manipulation Questions: • Find Set Bit In Intege...
Binary Tree Interview Question: • Invert Binary Tree
Sorting Algorithms: • Bubble Sort
C++ MCQ: • Video
C MCQ: • What printf returns af...
C Interview Questions: • Designated Initializat...
QUICK SHORT VIDEOS
-------------
C++ Short : • C++ Short Videos
C Short : • Shorts C Programming MCQ
TOPIC: Bit Fields In C++
POINTS:
1. It is used to reduce the size of "class/struct" if we can.
2. Force alignment is possible using unnamed bit fields of size 0.
#computerscience #tutorial #programming #computerscience #softwareengineering

Пікірлер: 107
@hindiistoriess
@hindiistoriess 8 ай бұрын
Thank you 🙏🏻 for explaining in detail... Now I understood fully about bit fields
@janupenaganti4951
@janupenaganti4951 4 ай бұрын
I have started my career in Embedded Systems, this topic is really helpful for me. Thank you!!
@treyquattro
@treyquattro 3 жыл бұрын
I appreciate the work you put into these videos and your professorial style. The videos are a great resource for newbies and also as a refresher for some of us who like to keep our memories refreshed!
@CppNuts
@CppNuts 3 жыл бұрын
Thanks man!!
@nishantgarg5324
@nishantgarg5324 6 жыл бұрын
Nice illustrate. Keep it up.
@CppNuts
@CppNuts 6 жыл бұрын
Thanks Dude!!
@vimleshkumarkanaujiya
@vimleshkumarkanaujiya Жыл бұрын
Arey Bhaiya, What an easy way of teaching !.
@Gautamdange
@Gautamdange 4 жыл бұрын
Really liked your videos .. simple .. short and to the point !
@CppNuts
@CppNuts 4 жыл бұрын
Thanks.. Man..!!
@pandemade3875
@pandemade3875 4 жыл бұрын
Thank you so much! This really helps me understand bit field in more detail! Thank you!
@CppNuts
@CppNuts 4 жыл бұрын
Glad that it helped.
@sss-og7jx
@sss-og7jx 2 жыл бұрын
Very Clear! Thank U!
@sabanaafrose7293
@sabanaafrose7293 6 жыл бұрын
Superb... Keep doing... The way you explained the flow and the sequence ... Everything made me hit like ..if I could I would hit it many times.... Thank a lot
@CppNuts
@CppNuts 6 жыл бұрын
Sabana Afrose, Thanks for your like and nice comment.
@sambasivamupparaju
@sambasivamupparaju 6 жыл бұрын
good explanation. Thank you for your effort .
@CppNuts
@CppNuts 6 жыл бұрын
Thank man:!!
@ViratKohli18_Lovers
@ViratKohli18_Lovers 6 жыл бұрын
You explained it very well sir. I understood everything about bit field.
@CppNuts
@CppNuts 6 жыл бұрын
That's great!!
@soumyaranjansahu7018
@soumyaranjansahu7018 4 жыл бұрын
Awesome explanation...😊👍
@Olavotemrazaodenovo
@Olavotemrazaodenovo 4 жыл бұрын
Congratulations from Brazil.
@CppNuts
@CppNuts 4 жыл бұрын
Thanks man!!
@rajcodes100
@rajcodes100 5 жыл бұрын
Great explanations - thank you
@CppNuts
@CppNuts 5 жыл бұрын
Thanks for your comment!!
@aadarshraj5859
@aadarshraj5859 2 жыл бұрын
Very nice explanation. Thanks to you
@CppNuts
@CppNuts 2 жыл бұрын
Thanks
@vvpChannel3112
@vvpChannel3112 4 жыл бұрын
Awesome video sir.. I learnt something new here...many thanks ..please make more videos on memory optimisation
@CppNuts
@CppNuts 4 жыл бұрын
Sure man i will try for this video.
@maratheps1new237
@maratheps1new237 2 жыл бұрын
sir your all cpp videos are great ^^
@CppNuts
@CppNuts 2 жыл бұрын
Glad you like them!
@ofirfr4804
@ofirfr4804 4 жыл бұрын
Very good explanation. I learned a lot.
@CppNuts
@CppNuts 4 жыл бұрын
Glad it was helpful!
@vipuldogra6600
@vipuldogra6600 4 жыл бұрын
beautifully explained. thanks
@CppNuts
@CppNuts 4 жыл бұрын
Thanks man!!
@cid007007
@cid007007 4 жыл бұрын
Great tutorial.. learnt alot.. :)
@CppNuts
@CppNuts 4 жыл бұрын
Thanks...
@karthikkumarmv9101
@karthikkumarmv9101 4 жыл бұрын
So nice and effective explanation Sir tq. ...
@CppNuts
@CppNuts 4 жыл бұрын
Thanks bro..
@bilgetaskn9428
@bilgetaskn9428 4 жыл бұрын
it was amazing.. thank you so much
@CppNuts
@CppNuts 4 жыл бұрын
Glad you liked it!
@shiwanisingh3152
@shiwanisingh3152 5 жыл бұрын
Very helpful sir Thank you sir
@CppNuts
@CppNuts 5 жыл бұрын
Most welcome!!
@KumarGaurav159
@KumarGaurav159 6 жыл бұрын
It was very helpful and I request to upload a tutorial regarding forward declaration in c++ in details and with depth analysis.thanks .
@CppNuts
@CppNuts 6 жыл бұрын
I am trying my best to upload as much as i can but i will keep this suggestion in my mind thanks dude!! :)
@shibisaketh
@shibisaketh 5 жыл бұрын
unsigned int day : 5; unsigned int month : 4; int year : 22; So can reduce the size again. Size : 4
@CppNuts
@CppNuts 5 жыл бұрын
Yes you can further use the same int for 1 Bit because 5+4+22 = 31 and int is 32 bits.
@Agogogogogogkglgkfndjesk
@Agogogogogogkglgkfndjesk 4 жыл бұрын
thank you for the explanation sir
@CppNuts
@CppNuts 4 жыл бұрын
You are welcome dude..
@AhmedKhaled72
@AhmedKhaled72 3 жыл бұрын
The best teacher out there 😍😍
@CppNuts
@CppNuts 3 жыл бұрын
Thanks man..
@AshokKumar-mk1nr
@AshokKumar-mk1nr 4 жыл бұрын
Awesome explanation..
@CppNuts
@CppNuts 4 жыл бұрын
Thanks man!!
@1-User-1
@1-User-1 5 жыл бұрын
Best explanation of Bit Fields.
@CppNuts
@CppNuts 5 жыл бұрын
Thanks for the comment man!!
@1-User-1
@1-User-1 5 жыл бұрын
@@CppNuts thank you for your video!
@jaganmohanroyalnanubala3095
@jaganmohanroyalnanubala3095 Жыл бұрын
Loved it 💕
@CppNuts
@CppNuts Жыл бұрын
Thanks..
@amitpandey4566
@amitpandey4566 6 жыл бұрын
great as always
@CppNuts
@CppNuts 6 жыл бұрын
Thanks dude!!
@satishkanakappanavar8531
@satishkanakappanavar8531 5 жыл бұрын
Thank you
@CppNuts
@CppNuts 5 жыл бұрын
Satish, welcome dude.
@mohanrajawat6508
@mohanrajawat6508 4 жыл бұрын
very nice discription
@CppNuts
@CppNuts 4 жыл бұрын
Thanks man!!
@mukundshahiitr7113
@mukundshahiitr7113 3 жыл бұрын
Nice explaination☺☺
@CppNuts
@CppNuts 3 жыл бұрын
It's my pleasure
@user-ts4cz9fs1j
@user-ts4cz9fs1j 10 ай бұрын
8:51 sir, Why structural packing doesn't work in the above example it still give 8 bytes of size On adding #pragma pack(1)
@ShivamSingh-ub9tg
@ShivamSingh-ub9tg 5 жыл бұрын
nice tut. :)
@CppNuts
@CppNuts 4 жыл бұрын
Thanks man!!
@willbecker7100
@willbecker7100 3 жыл бұрын
can you help me with allocating memory for black ops 3 for a mod. I want to add more assets into attachmentunique
@shivamsaxena5854
@shivamsaxena5854 4 жыл бұрын
#include #include struct d0 { char vo : 3; int v1 : 7; }; int main() { printf("%d", sizeof(struct d0)); return 0; } I thought that I shall get 4 bytes as output as 32 bits (size of larger data type i.e; int) are enough to store 3 bits of char and 7 bits of int data type, But instead, I'm getting 8 bytes as output. Please tell me why I am getting so? Please answer @CppNuts
@_shubham_kumar
@_shubham_kumar 4 жыл бұрын
Great video. But I don't understand why we can't have static variables with bit fields?
@CppNuts
@CppNuts 4 жыл бұрын
Why do you want that?
@helloyou4233
@helloyou4233 4 жыл бұрын
it was nice
@CppNuts
@CppNuts 4 жыл бұрын
Thanks man!!
@SYALUS3
@SYALUS3 6 жыл бұрын
Very good explanatuion... But one doubt actually we couldn't use that saved memory. Then why....
@CppNuts
@CppNuts 6 жыл бұрын
Notice that when we didn't use bit fields size was 12 but when we used bit fields then size became 8.
@matheenshk
@matheenshk 4 жыл бұрын
nice
@CppNuts
@CppNuts 4 жыл бұрын
Thanks
@abdullahgarra8477
@abdullahgarra8477 9 ай бұрын
Hi, I have an interview and the interviewer said I should be handy with bitfields where can i see questions ?
@CppNuts
@CppNuts 9 ай бұрын
I have bit field questions series plz check that out.
@hitendrapalsinghrao3436
@hitendrapalsinghrao3436 6 жыл бұрын
What is the software you are using?
@CppNuts
@CppNuts 6 жыл бұрын
It is Sublime Text Editor 3.
@hitendrapalsinghrao3436
@hitendrapalsinghrao3436 6 жыл бұрын
Btw very good video!!
@CppNuts
@CppNuts 6 жыл бұрын
Thanks dude!!
@mdirshadalam2617
@mdirshadalam2617 5 жыл бұрын
How will allocate 16 bytes or 32 bytes in bit fields or large size? I need this very much.Please explain
@CppNuts
@CppNuts 4 жыл бұрын
Please explain more, couldn't understand your question?
@mdirshadalam2617
@mdirshadalam2617 4 жыл бұрын
@@CppNuts Is there any restriction for allocating bit in bit fields? Means, how many bits to allocate in bit field or no restriction.
@CppNuts
@CppNuts 4 жыл бұрын
Yes it is max of the type used. For more check this stackoverflow.com/questions/14553632/maximum-size-of-a-bit-field-in-c-or-c
@mdirshadalam2617
@mdirshadalam2617 4 жыл бұрын
@@CppNuts Thank
@justcurious1940
@justcurious1940 Жыл бұрын
struct date { unsigned char day : 5 ; unsigned char month : 4 ; unsigned char year ; } ; printf("sizeof struct date : %d ",sizeof(struct date)) ; // output is 3 i'm using gcc default compilation .
@CppNuts
@CppNuts Жыл бұрын
Year one byte Day + month is 2 bytes, because 5+4 is 9 bits which is more than one byte.
@justcurious1940
@justcurious1940 Жыл бұрын
@@CppNuts Thank u for replying, my confusion was that the size of( struct date) is not a power of 2 or a multiple of 2, I thought that objects in C always occupies a space in memory that is either a power of 2 or a multiple of 2.
@CppNuts
@CppNuts Жыл бұрын
That is multiple of biggest data member in class or struct.
@justcurious1940
@justcurious1940 Жыл бұрын
@@CppNuts yes, Thank u I get it now.Great video by the way, so much information gained.
@paul87173
@paul87173 4 жыл бұрын
Hey Yadav, i'm learning c++ by myself. Any comments or tips you cud giv me? I have no money to go to university. But Still i want to be a programmer.
@CppNuts
@CppNuts 4 жыл бұрын
Work hard like your life depends on it.
@paul87173
@paul87173 4 жыл бұрын
@@CppNuts C'mon dude,please give me more props.I mean, your fav book, anyhobbies concerning c++, you know.. that sort of things.
@CppNuts
@CppNuts 4 жыл бұрын
Doesn't really matter.
@tahirm09
@tahirm09 6 жыл бұрын
hi, voice is not clear pl check
@CppNuts
@CppNuts 6 жыл бұрын
At what point did you feel that? Please mention the timing in the video. Thanks
@WowPlusWow
@WowPlusWow 2 жыл бұрын
🙏🏼🙏🏼🙏🏼🙏🏼🙏🏼🙏🏼
@CppNuts
@CppNuts 2 жыл бұрын
Namaste..
@prakashkondru5020
@prakashkondru5020 3 жыл бұрын
Sir plz tell me your git hub . I will copy the code
@CppNuts
@CppNuts 3 жыл бұрын
I am working on it.
@vasubansal8438
@vasubansal8438 3 жыл бұрын
Voice is too less
@CppNuts
@CppNuts 3 жыл бұрын
Sorry for that..
@smartmiran
@smartmiran 3 жыл бұрын
why does he need to place advertisement every 2 seconds, this is really annoying!!
Operator Overloading In C++
13:50
CppNuts
Рет қаралды 52 М.
Overloading new And delete Operator In C++
21:59
CppNuts
Рет қаралды 22 М.
Задержи дыхание дольше всех!
00:42
Аришнев
Рет қаралды 3,7 МЛН
Playing hide and seek with my dog 🐶
00:25
Zach King
Рет қаралды 36 МЛН
Bit-fields in C (+1 Design Problem) | Sanfoundry
32:04
Sanfoundry
Рет қаралды 6 М.
How do I access a single bit?
11:07
Jacob Sorber
Рет қаралды 20 М.
Overloading Function Template In C++
19:32
CppNuts
Рет қаралды 14 М.
C++ Bit Fields
30:01
Creel
Рет қаралды 15 М.
Water powered timers hidden in public restrooms
13:12
Steve Mould
Рет қаралды 738 М.
When do I use a union in C or C++, instead of a struct?
11:18
Jacob Sorber
Рет қаралды 68 М.
C++ Bitsets in Competitive Programming
15:35
Errichto Algorithms
Рет қаралды 117 М.
PHP doesn't suck (anymore)
10:48
Aaron Francis
Рет қаралды 202 М.
Bit Fields in C. What are they, and how do I use them?
13:26
Jacob Sorber
Рет қаралды 80 М.
Задержи дыхание дольше всех!
00:42
Аришнев
Рет қаралды 3,7 МЛН