C# Interview Questions :- Stack Heap in C#| Boxing Unboxing in C# | Value Type Reference Type in C#

  Рет қаралды 38,960

Questpond

Questpond

Күн бұрын

For more Interview Q&A videos www.questpond.com
In this video we have covered 21 Interview Questions related to Boxing, Unboxing, Value Type , Reference Type, Stack & Heap.
00:00 :Introduction
01:58 Question 1:- Explain stack and Heap ?
02:46 Question 2:- Where are stack and heap stored ?
03:15 Question 3:- What goes on stack and what goes on heap ?
09:26 Question 4:- How is the stack memory address ?
11:02 Question 5:- How is stack memory deallocated LIFO or FIFO ?
14:01 Question 6:- How is memory and values stored primitive and ref ?
23:24 Question 7:- Can primitive data types be stored in heap ?
27:14 Question 8:- Explain value types and reference types ?
31:36 Question 9:- What is byval and byref ?
31:36 Question 10:- Differentiate on copy by value and copy by ref ?
32:44 Question 11:- What is boxing and unboxing ?
34:17 Question 12:- Is boxing unboxing good or bad ?
37:53 Question 13:- Can we avoid boxing and unboxing ?
45:08 Question 14:- What effect does boxing and unboxing
45:48 Question 15:- Are string allocated on stack or heap ?
47:15 Question 16:- How many stacks and heaps are created for an application ?
50:42 Question 17:- How are stack and heap memory deallocated ?
50:42 Question 18:- Who clears the heap memory ?
56:24 Question 19:- Where is structure allocated Stack or Heap ?
56:24 Question 20:- Are structures copy byval or copy byref ?
56:24 Question 21:- Can structures get created on Heap ?
Also see our other Step by Step video series below :-
For more such videos subscribe / questpondvideos
JavaScript Interview questions: • JavaScript Interview Q...
Learn SQL Server Step by Step tinyurl.com/ja4zmwu
Learn Angular tutorial step by step tinyurl.com/ycd9j895
ASP.NET MVC Core Interview Questions with answers:- • ASP.NET MVC Interview ...
C# interview questions and answers:- • C# Interview Questions...
C# tutorial for beginners(4 hrs):- • C# Tutorial for Beginn...
Learn Azure Step by Step:- • Azure Tutorial for Beg...
Azure AZ-900 fundamentals certification :- • AZ 900 Certification |...
AZ- 204 certification Azure:- • Azure 204 Certificatio...
Learn MVC 5 step by step in 16 hours:- • Learn ASP.NET MVC 5 ( ...
Learn Design Pattern Step by Step goo.gl/eJdn0m
Learn MSBI Step by Step in 32 hours:- goo.gl/TTpFZN
Python Tutorial for Beginners:- • Python Tutorial for Be...
Learn Data Science in 1 hour :- tinyurl.com/y5o7qbau
Learn Power BI Step by Step:- tinyurl.com/y6thhkxw
PHP Interview Questions : • PHP Interview Question...
-----------------------------------------------------------------------------------------------
For more details :-
🌐 Website : www.questpond.com
📱 Mob. No. : +91-9967590707 / +91 7700975156 / +91-22-49786776
📧Email : questpond@questpond.com / questpond@gmail.com / questpond@yahoo.com
Share, Support, Subscribe and Connect us on!!!
KZfaq: / questpondvideos
Twitter: / questpond
Instagram : / questpond
Facebook : / questpond

Пікірлер: 103
@questpondvideos
@questpondvideos Жыл бұрын
30 Important C# Interview Questions : kzfaq.info/get/bejne/eLGpoahztdfNeYE.html ASP.NET, C# Job Market : kzfaq.info/get/bejne/fpl6eLpy1ZmWXac.html 20+ Garbage Collection (GC) Interview Questions : kzfaq.info/get/bejne/iM2WqLmhl9K8eXU.html 25+ OOPS Interview Questions : kzfaq.info/get/bejne/q59pqqSgp9CopoU.html Software Architecture Interview Questions : kzfaq.info/get/bejne/d9qEmsaTsbXVfYE.html 20+ SQL Server Interview Questions : kzfaq.info/get/bejne/iauUdKlp0rmvg2g.html 10+ Power BI Interview Questions : kzfaq.info/get/bejne/edWqlpyIs6i2pGg.html 20 MSBI Interview Questions : kzfaq.info/get/bejne/hN2Ppqt2sNSzhXk.html SQL Server Joins : kzfaq.info/get/bejne/gbqmjKt209ranmw.html SQL Step by Step - kzfaq.info/get/bejne/q62cmbNq1J3PnY0.html Angular Step by Step Tutorial for Beginners : kzfaq.info/get/bejne/Y5-Glrposqioo2w.html 25 Angular Interview Questions : kzfaq.info/get/bejne/Y9CVotx1r6rXg4E.html 25 Important ASP.NET Interview Questions : kzfaq.info/get/bejne/pr6dgMeer7unYJs.html 35 Important JavaScript Interview Questions : kzfaq.info/get/bejne/kMhkl7OanKmlfok.html 20 MySQL Interview Questions : kzfaq.info/get/bejne/b86WnaZep9a9YmQ.html 5 MSBI Interview Questions : kzfaq.info/get/bejne/a6toZJiSvafbiYU.html 20 PHP Interview Questions : kzfaq.info/get/bejne/Z8iggbaq07vWnGw.html
@neerajsharma1055
@neerajsharma1055 Жыл бұрын
19. Structure is allocated on Stack 20. Structures are copy byVal 21. Yes, Structures can get created on heap if they are fields of a class
@questpondvideos
@questpondvideos Жыл бұрын
perfect.
@Fireballl14
@Fireballl14 8 ай бұрын
This first and only video that managed to explain to me how stack and heap works. You sir deserve a medal for this one!
@zaharivaklinov
@zaharivaklinov Жыл бұрын
Awesome job, Shiv. You helped me land my entry-level job in my software development career.
@koushikhalder1579
@koushikhalder1579 Жыл бұрын
Its a perfect explanation 19) Structure gets allocated on stack 20) Here the structure is copy by Val not copy by ref 21)Yes we may create structure on heap memory also overall Today few of my doubts regarding memory allocation of a program gets cleared Thank you for such knowledgeable video...
@mel8969
@mel8969 Жыл бұрын
Thank you Shiv, this is one of the best and most well explained videos I've ever watched on these subjects. I'm not even interviewing as I'm just learning C# and I absolutely loved how easy you made this. I hope you continue to deep dive into more C# content! I subscribed and plan on signing up to your website courses, Thank you again!
@trangkd3314
@trangkd3314 Жыл бұрын
Q19: Structure alloc on Stack Q20: MyStruct s2 = s1; It's copied byValue Q21: Structure can be alloc on Heap when an object has structure property -- Thank you so much for the lesson!
@rmatube
@rmatube Жыл бұрын
Best and most experienced .Net trainer gives another great example of in depth concepts in easily understandable method
@rameezshaikh5699
@rameezshaikh5699 Жыл бұрын
Thanks a lot sir, I have been watching your videos since 2013...By watching your videos I cracked my interviews for L&T infotech, Arees Software, JLL, Qualsoft systems...🙂
@MikeKm-hd1ve
@MikeKm-hd1ve 3 ай бұрын
Thank you for the most comprehensive video on youtube!! The three questions at the end of the video are asking about the same thing 19. structs are stored on stack, since they are primitive data types 20. byval 21. Yes, as a part of a class instance
@minitam1527
@minitam1527 Жыл бұрын
I didn't know how does memory allocation and deallocations works and you've shown it in so detailed and interesting way. Thank you so much. 🙂
@aleem076
@aleem076 Жыл бұрын
Thank you Shiv, your trainings are amazing, help me and many developers like me to be able to put things in decent way in the interview, otherwise many who did work can't explain things in proper way and step by step, that's amazing.
@ebindia83
@ebindia83 Жыл бұрын
Just awesome. Now I know and can relate how value type and reference types work behind the scene.
@raykwatts
@raykwatts 4 ай бұрын
Good teacher. Very thorough. This is how it’s done.
@AspDevs
@AspDevs Жыл бұрын
Too good. Best video on stack and heap.
@calmmantra1
@calmmantra1 Жыл бұрын
It's gem ! You are a life saver !! Thank-you!!!
@anoopkothapally5000
@anoopkothapally5000 9 ай бұрын
Great Video ShivPrasad , Thank you!
@michaelndukwe6151
@michaelndukwe6151 Жыл бұрын
You are gold! Thank you very much!
@pmro
@pmro Жыл бұрын
Great package of questions! There is one more thing about stack and heap, what happen in situations when we pass data to methods, and next when we pass data with OUT and REF prefixes :)
@mayuripatel3225
@mayuripatel3225 Жыл бұрын
Watching any of your video I consider topic I understand is 100% thank you so much for this detailed session
@rpunk1684
@rpunk1684 Жыл бұрын
Very comprehensive, thank you so much sir!
@saurabhm19782
@saurabhm19782 Жыл бұрын
Very nice explanation... watched full hr till end.. thank you
@sandeepsoni7162
@sandeepsoni7162 Жыл бұрын
Eye opener video .... ❤️
@jananiselvaraju4329
@jananiselvaraju4329 Жыл бұрын
Great explanation and thank you so much for this detailed session 👍
@yuvrajingale526
@yuvrajingale526 Жыл бұрын
What a fabulous teaching strategy . keep great work continues☺
@gururaghavendra6387
@gururaghavendra6387 8 ай бұрын
This is a wonderful explanation. Thank you very much. And yes we did see the sanitizer bottle too😊.
@user-xt9no8we4r
@user-xt9no8we4r 9 ай бұрын
Excellent Teaching Method. I Love your videos from Pakistan
@srirammkornapati5737
@srirammkornapati5737 Жыл бұрын
Thanks for your video Sir. It is amazing to clarify all of my doubts about memory parts.
@spiedey8
@spiedey8 7 ай бұрын
Good content, thank you!
@PI-Thoughts
@PI-Thoughts Жыл бұрын
many of your videos helped me a lot.
@mahmoudadel1232
@mahmoudadel1232 Жыл бұрын
Thank you so much, really you let me understand it 100%
@uttamkhawas9819
@uttamkhawas9819 Жыл бұрын
Crystal clear..💓
@sirajudinsiraj3330
@sirajudinsiraj3330 Жыл бұрын
It was very nice. Got good knowledge. Thank you sir. I have watched it completely
@marhamatabadi
@marhamatabadi 7 ай бұрын
it was awesome explaining around the subjects. thanks a lot
@ramanjitsingh5211
@ramanjitsingh5211 Жыл бұрын
I always liked your video. You are great instructor.
@ravimakwana389
@ravimakwana389 Жыл бұрын
boxing unboxing that why decreases performance never know, Thanks this is great
@chemis2115
@chemis2115 11 ай бұрын
Best tutor ever. Keep it up Sir 😍
@SandeepKumar-si3nz
@SandeepKumar-si3nz Жыл бұрын
For Q19 - stack For Q20 - by Val For Q21 - we can create heap as s3 representing the address reference that's mean heap created
@user-yo9lc5uo8h
@user-yo9lc5uo8h Жыл бұрын
Best explanation ever.😋
@utkarshgupta2943
@utkarshgupta2943 Жыл бұрын
Loved your videos
@asmeromfessehayehabteab5939
@asmeromfessehayehabteab5939 Жыл бұрын
Thank you so much Sir. Very nice explaniation. Keep up the good work
@TheRtpbuc
@TheRtpbuc 5 ай бұрын
I'll answer the question about the usefulness of these types of questions as an interviewer as opposed to more topical questions. I don't think these are deal breaker questions for junior to mid roles but, they do help identify a certain type of developer that you really want. If candidates can answer these questions correctly, demonstrate a topic specific knowledge necessary for the role, solve a design problem and answer behavioral questions well, they are a hire for me.
@arshikapatel9219
@arshikapatel9219 Жыл бұрын
1. Structure allocated in stack. 2. Structure copy byval. 3. yes, Structure can create in heap as well as in stack.
@dipikabhagat5252
@dipikabhagat5252 11 ай бұрын
Great explanation .really appreciate Sir .
@Gauravkumar-jm4ve
@Gauravkumar-jm4ve Жыл бұрын
thank u so much, wil share this video on linkedin
@RohithVarma36
@RohithVarma36 Жыл бұрын
The fact that there is no clear answer as to which school of thought we belong to doesn't imply that he shouldn't comprehend the basics (I STRONGLY RECOMMEND FUNDAMENTALS FIRST). A healthy balance between the first and second schools of thought, as well as an honest desire to learn, should exist. A person should not be tested on memory but rather on honesty and enthusiasm for learning new things. Because it's just a matter of memory and is accessible online, he might pick up the same idea the following day.
@digital.voyager
@digital.voyager 2 ай бұрын
19. Where is structure allocated Stack or Heap? - Stack, as you can clearly see in Quick watch that those values are stored in stack. 20. Are structures copy byval or copy byref? - Structs are copy byval, as you can see that after copying s1 to s2 its values are stored in stack & and address is not stored. 21. Can structures get created on Heap? - Yes, they will get created if they are part of a object. I have one doubt. If any value type is stored in heap like if struct is stored in heap then is it directly stored in memory or it is stored in another stack and that stacks memory address is stored in heap? May b stupid question but could you please clear my doubt? @questpondvideos
@Syberianoir
@Syberianoir Жыл бұрын
Thank you for your trainings, love it. 19) structure are allocated in stack. 20) are copy byVal. 21) Is possible created in heap.
@SLHooLigON
@SLHooLigON Жыл бұрын
Well explained.
@mohammedsajjadahmed4484
@mohammedsajjadahmed4484 7 ай бұрын
Shiv you are really good at explaining things easy and smooth For the past 9 years, i always prefer your videos for any learning or job change. You are doing a great job, your voice tone is really impressive
@questpondvideos
@questpondvideos 7 ай бұрын
Thank you for your kind words :)
@chandansahoo466
@chandansahoo466 Жыл бұрын
Thank you so much Sir 🙏
@eammonmsetfi2763
@eammonmsetfi2763 9 ай бұрын
Really informative. Makes the info stick by giving examples rather than regurgitating info from a book many thanks
@manivasakamr
@manivasakamr 6 ай бұрын
Well explained
@vemankunoor695
@vemankunoor695 Жыл бұрын
Thank you for use full video
@hareshce2009
@hareshce2009 6 ай бұрын
Q19: memory stores direct value, so it is stack Q20: ByValue Q21: Yes because heap because is part of oject t
@Jayant171992
@Jayant171992 Жыл бұрын
Stack, byval, heap and thank you 🙂
@lahirureshanwanniachchi9065
@lahirureshanwanniachchi9065 8 ай бұрын
Very usefull thank you
@rpchost
@rpchost 11 ай бұрын
Thank you for this great video, very easy to follow you. I think a software engineer should know the basic things like stack and heap, boxing unboxing etc ..
@nskarsri
@nskarsri 8 ай бұрын
19) structures are allocated on stack. 20) structure follows copy byval 21) structure get created on the heap when that is part of instance.
@AravindKumar-lj7kx
@AravindKumar-lj7kx Жыл бұрын
A simple answer to all the last 3 questions can be that primitive data types like int,double are structure in nature. Thank you for the great tutorial. Please correct me if I am wrong
@veerabubali2245
@veerabubali2245 Жыл бұрын
Nice
@lakshayrcksParkour
@lakshayrcksParkour Жыл бұрын
Thank you sir
@pazhanikumar8584
@pazhanikumar8584 5 ай бұрын
nice exp
@being_aslam_tiger
@being_aslam_tiger Жыл бұрын
Thanks you.
@CsharpSpace
@CsharpSpace Жыл бұрын
Sir your way of explanation is always awesome 😊
@questpondvideos
@questpondvideos Жыл бұрын
Thanks nice name....:-) and good to see you running a technical channel.
@dipikabhagat5252
@dipikabhagat5252 11 ай бұрын
19. Stack 20.byval 21.Yes if they are properties of an object
@elfyjohnson261
@elfyjohnson261 Жыл бұрын
I wish you were my teacher when I was in college.
@eammonmsetfi2763
@eammonmsetfi2763 9 ай бұрын
19: Structures are value types. Will be stored on the stack but can be stored on both the heap when used in a class instance. 20) Structures use copy val, and will create a new reference in the ram for the value. 21) yes if they are used within an object, for example if my employee class used a structs to store values, the structs within the employee object would be added to the heap That’s my take on it so far have just paused the video without reading comments so I hope I have it right 😅
@sonalidatta810
@sonalidatta810 Жыл бұрын
Thank you so much Sir. 🙏 The structure gets allocated in stack. Structure are copied byval. Structure can be created on heap.
@questpondvideos
@questpondvideos Жыл бұрын
Bravo and you are so right
@amansharma-zo2zd
@amansharma-zo2zd 9 ай бұрын
@subat4753
@subat4753 4 ай бұрын
structure s1, s2 is allocated on stack but s3 is refernce the structure is created on heap by giving reference on stack
@priyanshurastogi6057
@priyanshurastogi6057 Жыл бұрын
Thank you sir, it's a wonderful explanation. You have talk about each and everything. But as you say there's challange to clear heap. So new programing language/technology coming in market still they are using concept of heap. If yes then What is the main dependency on heap which is making it necessary to use
@mwaseemzakir
@mwaseemzakir 10 ай бұрын
As per August 2023 , things have changed now , I created same example now on Visual Studio and everything was being stored on stack now, correct me if I am wrong.
@niteshkumarsaw2771
@niteshkumarsaw2771 Жыл бұрын
Hi Questpond, Thanks for uploading such a nice videos on Stack/heap. Below is the answer for the 19,20 & 21. 19. Stack - because structure are value type. 20. Structure copy byval , and we can see that when you wrote &S2. It is directly showing the value instead address of value. 21. Yes , structures can be created in heap when we use as member in class. Here structure is member of class. I hope , i am able to answer last 3 question correctly, if not then please correct me. Thanks
@questpondvideos
@questpondvideos Жыл бұрын
Yo are super right and very nicely put.
@changemaker9751
@changemaker9751 7 ай бұрын
what if we add a string as a variable in a struct and that struct is called in a function ? . I tried it and it says it is located in the heap not the stack. Adresses are different
@faisalzubair2612
@faisalzubair2612 Жыл бұрын
Structures created on stack. Copy by val. Structures can be created on heap.
@itsmevaibhav007
@itsmevaibhav007 Жыл бұрын
S1 = Stack, S2 = Stack, S3 = Heap
@yogendramaurya4993
@yogendramaurya4993 4 ай бұрын
Can anyone explain me whether unboxing is happening in below code? As per definition ,obj (Age and Name) is stored on heap and we are retreiving Name field from heap memory to local variable Age into stack memory. internal class Program { static void Main(string[] args) { Test obj = new Test(); int Age = Convert.ToInt32(obj.Name); // is there any unboxing here at this line } } internal class Test { public int Age = 10; public string Name = "150"; }
@ghulammustafajagirani8380
@ghulammustafajagirani8380 Жыл бұрын
Dear Sir W Asslam
@niteshkumarsaw2771
@niteshkumarsaw2771 Жыл бұрын
Hi Questpond, Is it possible to share the interview question documents with us? That you are talking about in this video. Thanks
@questpondvideos
@questpondvideos Жыл бұрын
After sharing the video send us email to get free ebook.
@anurag3487
@anurag3487 Ай бұрын
One question - why are actual objects stored on heap?
@vinothrajendran6993
@vinothrajendran6993 9 ай бұрын
Sir I have a question. Why can't object values be stored on stack? Just because the values are keep changing?
@subha1250
@subha1250 6 ай бұрын
Hello Sir, Can you please explain what will be the memory allocation for a child object. For example Student in following case Class.Student.StudName
@user-xg7hi5mh3g
@user-xg7hi5mh3g Жыл бұрын
Why is the value with 16 digits is it in hexadecimal so haw many Bytes/bits is required? Could anyone make this clear for me ? And between 408 and 404 is it 4 ?? ? Whzt the unit of the diffrence 408-404 = ?? Is it the size of the variable for example xbool here
@suhaskamble7571
@suhaskamble7571 Жыл бұрын
Sir Is it useful for .net developers to learn mongodb and nodejs ??
@questpondvideos
@questpondvideos Жыл бұрын
It's optional and depends on the project requirement which you are working on. Yes it is useful to learn mongodb and nodejs due to demand being very high.
@MonirulIslamsondhymoni
@MonirulIslamsondhymoni Жыл бұрын
S1 Allocated to Stack S2 struct is copy byVal S3 Yes! It's gose in to heap
@yosofjoo
@yosofjoo 7 ай бұрын
I want to get the e-book,,please
@TonyTigerTonyTiger
@TonyTigerTonyTiger Жыл бұрын
The addresses can be confusing if you don't realize that in memory, stacks grown DOWN, not up. Logically, when something new gets put onto a stack, it gets put on top of everything already in the stack. So a stack grows from bottom (lowest memory address) upwards (highest memory address). But that is not how a stack behaves physically. Instead, the first element of the stack is stored at the HIGHEST memory location available for the stack, and each new element is stored BELOW the prior element. So in memory, a stack starts at the top and grows downward.
@questpondvideos
@questpondvideos Жыл бұрын
The diagrams are obviously for understanding purpose so it does not resemble the exact structure internally. Said and done how stack is allocated like top to bottom or vice versa is completely architecture dependent. Many architectures follow what you say but also there are few who do not.
@maheshbhatchandavar
@maheshbhatchandavar Жыл бұрын
How to get the eBook sir? Do you want me to share the screenshots that I have shared this over facebook?
@questpondvideos
@questpondvideos Жыл бұрын
Yes send email to us, steps for getting free ebook are mentioned in the videos.
@battuhant
@battuhant 5 ай бұрын
where are functions belonging to class stored. and functions local variables
@user-xt9no8we4r
@user-xt9no8we4r 9 ай бұрын
Question 19:- Where is the structure allocated Stack or Heap ? Answer: In C#, when you create a structure (struct), it is typically allocated on the stack if it's a local variable within a function or method. However, if the structure contains reference types (e.g., objects), those reference types will be allocated on the heap, and the structure will store references to them. Question 20:- Are structures copy byval or copy byref ? Answer: Structures are mostly copy by values but if it contains an object then it will be copy by reference. Question 21:- Can structures get created on Heap ? Answer: Structures are mostly created on stack but if it contains an object then the object gets created on stack.
@user-xt9no8we4r
@user-xt9no8we4r 9 ай бұрын
Please check my answers and tell me about the questions are correct. If not correct then explain me please
@sunnybadgujar4467
@sunnybadgujar4467 Жыл бұрын
sorry sir i don't like it i love it best explanation sir :)
@antonfesenko920
@antonfesenko920 Жыл бұрын
Thank you sir
Backstage 🤫 tutorial #elsarca #tiktok
00:13
Elsa Arca
Рет қаралды 47 МЛН
Why You Should Always Help Others ❤️
00:40
Alan Chikin Chow
Рет қаралды 134 МЛН
1 класс vs 11 класс  (игрушка)
00:30
БЕРТ
Рет қаралды 4,4 МЛН
C# Fundamentals - Stack, Heap, and References
30:42
Rainer Stropek
Рет қаралды 2,2 М.
C# | Interview Question | Value type vs Reference Type
9:47
Rohit Sharma
Рет қаралды 13 М.
9. Java Memory Management and Garbage Collection in Depth
48:48
Concept && Coding - by Shrayansh
Рет қаралды 47 М.
WHY IS THE STACK SO FAST?
13:46
Core Dumped
Рет қаралды 137 М.
Stack vs Heap Memory - Simple Explanation
5:28
Alex Hyett
Рет қаралды 197 М.
Backstage 🤫 tutorial #elsarca #tiktok
00:13
Elsa Arca
Рет қаралды 47 МЛН