이번에 C++ 인터뷰를 준비하면서 예상 질문 리스트를 만들어봤다. 이걸 블로그에 공유해볼까 한다.
영어 인터뷰였기 때문에 질문과 답변도 영어로 작성되어 있다.
내가 본 인터뷰의 후기를 간단히 말하자면, C++ 관련 질문은 경험이 있다면 쉽게 대답할 수 있는 내용이 많았지만, 오히려 다른 전공 도메인 관련 질문이 더 까다로웠다... 🥲
실제로 받았던 질문에는 형광펜 표시를 해서 따로 강조해 보겠다. :) 🖊️
C++의 practical 경험이 있다 하더라도, technical interview를 앞두고 이론적인 부분을 한 번 쭉 훑어본 것이 정말 큰 도움이 되었다. 🙌
1. Basic Concepts
What is the difference between C++
and C
?
OOP
- C: Does not support OOP concepts. Everything is done using functions and structs.
- C++: Supports OOP, allowing the creation of objects, encapsulation, inheritance, and polymorphism.
Standard Template Library (STL)
- C: No built-in data structures like vectors, stacks, or queues. The user has to implement them manually.
- C++: Provides a powerful Standard Template Library (
STL
), which includes data structures like vectors, lists, sets, and algorithms for searching, sorting, etc.
Memory Management
- C: Memory management is manual, using functions like
malloc()
,calloc()
,realloc()
, andfree()
. - C++: Provides
new
anddelete
operators for dynamic memory allocation and deallocation, making it easier and more intuitive to handle memory.
Explain the concept of pointers and how they work in C++
.
Pointers are variables that store the memory address of another variable. They are a fundamental feature in C++
and are used for various tasks like:
- Dynamic memory allocation.
- Passing large structures or classes to functions efficiently.
- Manipulating arrays and data structures.
What are references in C++
? How are they different from pointers?
References are an alternative to pointers for referring to variables. They are often used to:
- Pass arguments to functions to avoid copying.
- Create aliases for variables.
Key Differences:
- Pass by Value: Creates a copy of the object, which can be inefficient for large objects.
- Pass by Reference: Passes a reference (or address) to the original object, which is more efficient and avoids unnecessary copying.
- Const Reference: Allows efficient passing of objects while ensuring that they are not modified.
Explain the difference between new
and malloc
.
malloc
:- Allocates raw memory.
- Requires explicit casting and manual error handling.
- Does not call constructors or destructors.
new
:- More powerful and type-safe.
- Automatically calls constructors and destructors.
- Throws exceptions on failure instead of returning
NULL
.
What are destructors, and why are they used?
Destructors are special member functions in C++
classes that are called when an object of that class is destroyed. They are used to:
- Perform cleanup operations.
- Release resources that the object may have acquired during its lifetime.
What is a namespace in C++
?
A namespace
in C++
is used to:
- Group code under a specific name, preventing name conflicts.
- Improve code organization.
Usage:
- Access members of a namespace using the scope resolution operator
::
. - The
using
keyword can simplify access to elements in a namespace but should be used cautiously to avoid conflicts.
Python vs C++
C++
: Offers high performance, fine-grained control, and manual memory management, making it suitable for system-level programming and performance-critical applications. It has a complex syntax and requires explicit management of resources.- Python: Prioritizes ease of use, readability, and rapid development. It features automatic memory management, a rich standard library, and is well-suited for scripting, web development, and data analysis. While its interpreted nature and dynamic typing make it less performant than
C++
, Python is more flexible and developer-friendly.
배움을 기록하기 위한 공간입니다.
수정이 필요한 내용이나 공유하고 싶은 것이 있다면 언제든 댓글로 남겨주시면 환영입니다 :D
'배움 기록 > Programming' 카테고리의 다른 글
C++ 인터뷰 준비하기 - 2. OOP (3) | 2024.12.25 |
---|---|
[Github actions] CI 구축하기 (feat. workflow yaml파일) (2) | 2024.03.01 |
[python] (unittest.main) is not callable 에러 해결 (feat. PYTHONPATH, 환경변수) (0) | 2024.02.27 |
[python, dataclass] 데이터 클래스의 장점 (0) | 2024.02.26 |
csv파일을 엑셀에서 세미콜론으로 분리해서 보기 (데이터 변형 없이!) (1) | 2024.01.11 |