I'll give this guy 6 of 10. Q1 + Q2 are quite stupid, you should never mess with the stack and heap in a way that was not intended. If you are not a compiler developer - end of discussion... Size of the structs matter even today in many cases, for example - keeping cache alignment, when working with GPUs. #ifdef #endif have a lot of usages. Include guards are not the best example, since most compilers have #pragma once which is faster. NULL is basically for C programming, while nullptr is for C++. NULL is still used in legacy code, low level WIN32 programming, and one should follow the general convention there.
Q1. If the local variable is living in stack frame of another thread, the access of that memory piece is valid through a pointer from another thread until the threads are running. Although some lifetime management and synchronisation are needed. Q3: Size of the structs can be important regarding different communication protocols and their packets.
Yes. I'd recommend u to read smth about data structure alignment in C++. Actually, it's very cool to understand how architecture of computer processor manage all this work with memory and why on earth this padding happened.
hahaha the laugh stock comment is: "this was a concern back in the days when memory size was a concern". My man, you do embedded nowadays and you better mind the memory usage
It took you forever to get to the point. These don't sound like C++ questions... They're too basic. This is like... Guy right out of college level...? Im sure your good man.. I just wanted more questions about the language and less about how pointers work.
I mean you didn't cover things like virutal inheritance how it works in multiple inheritance. The new Lambdas C++ supports. The mutex, critical section classes... Whats new in std template library stuff like that... You just sorta noodle noised on basic stack allocation during method calls. Is this really how C++ interviews are conducted? I expected more code, patterns and newer features and less explanation about boiler plate interactions of heap and stack.
Nice point, but for those reading this is somewhat of a “clever” solution (not in a good way) and I would never say this in an interview. It’s frankly a kludge. Any programmer who jumps to this as a potential solution would immediately set off red flags for me. Code would be totally unmanageable, hard to read, dangerously subject to memory leaks. If you need dynamic memory, use the heap. If you need to pass values down function calls by reference, you should be passing by reference. If you need static memory, allocate it statically. Don’t do this as a workaround for any of those three.
I'll give this guy 6 of 10. Q1 + Q2 are quite stupid, you should never mess with the stack and heap in a way that was not intended. If you are not a compiler developer - end of discussion... Size of the structs matter even today in many cases, for example - keeping cache alignment, when working with GPUs. #ifdef #endif have a lot of usages. Include guards are not the best example, since most compilers have #pragma once which is faster. NULL is basically for C programming, while nullptr is for C++. NULL is still used in legacy code, low level WIN32 programming, and one should follow the general convention there.
Q1. If the local variable is living in stack frame of another thread, the access of that memory piece is valid through a pointer from another thread until the threads are running. Although some lifetime management and synchronisation are needed.
Q3: Size of the structs can be important regarding different communication protocols and their packets.
Q3: So designing it like this makes more sense, right?
struct TStruct
{
char a;
char b;
short c;
int d;
};
Yes.
I'd recommend u to read smth about data structure alignment in C++. Actually, it's very cool to understand how architecture of computer processor manage all this work with memory and why on earth this padding happened.
Thanks man
Microsoft asks such school level questions.😅Shame !
useful info: keyword new - calls the constructor
keyword delete - calls the destructor.
Hit like, if you didn't know 'bout this.
Great job!
#1, create another dummy function. this will most likely prove your point.
He looks so much like benedict. :D
hahaha the laugh stock comment is: "this was a concern back in the days when memory size was a concern". My man, you do embedded nowadays and you better mind the memory usage
Awesome
oy prashant babu!
Isn't that beginner level..?
I believe yes
It took you forever to get to the point. These don't sound like C++ questions... They're too basic. This is like... Guy right out of college level...?
Im sure your good man.. I just wanted more questions about the language and less about how pointers work.
I mean you didn't cover things like virutal inheritance how it works in multiple inheritance. The new Lambdas C++ supports. The mutex, critical section classes... Whats new in std template library stuff like that...
You just sorta noodle noised on basic stack allocation during method calls. Is this really how C++ interviews are conducted? I expected more code, patterns and newer features and less explanation about boiler plate interactions of heap and stack.
call to foo(NULL) is ambiguous in most compilers and leads to a compilation error, it's bad example imo
what the hell are you talking about NULL is defined as 0 and for compatibilityreasons whidely used instead of nullptr. WTF ^^
@@GrowBullet run cpp.sh/8zqjo, go back to school and do not post your stupid comments
Eazy
:)
#1. you can do this, if you use shared_ptrs
Nice point, but for those reading this is somewhat of a “clever” solution (not in a good way) and I would never say this in an interview. It’s frankly a kludge.
Any programmer who jumps to this as a potential solution would immediately set off red flags for me. Code would be totally unmanageable, hard to read, dangerously subject to memory leaks.
If you need dynamic memory, use the heap. If you need to pass values down function calls by reference, you should be passing by reference. If you need static memory, allocate it statically. Don’t do this as a workaround for any of those three.