search
HomeBackend DevelopmentC#.Net TutorialHow many of these 19 C/C+ interview questions can you answer correctly? - Personal article Sifu

What is the difference between C and C? Answer: c adds classes on the basis of c. C is a structured language whose focus is on algorithms and data structures. The interview routines for software engineers are all the same. You may encounter the same questions you asked this time, next time.

Question 1: Please tell me what C is in simple language?

Answer: C is an object-oriented programming language developed on the basis of C language and is widely used. C supports multiple programming paradigms - object-oriented programming, generic programming and procedural programming. It has a wide range of programming fields and is often used in system development, engine development and other application fields. It is one of the most powerful programming languages ​​​​used by programmers. It supports classes: classes, encapsulation, overloading and other features!

Question 2: What is the difference between C and C?

Answer: c adds classes on the basis of c. C is a structured language, and its focus is on algorithms and data structures. The primary consideration in the design of a C program is how to process the input (or environmental conditions) to obtain the output (or implement process (transaction) control) through a process. For C, the primary consideration is how to construct an object model so that This model can fit the corresponding problem domain, so that output or process (transaction) control can be achieved by obtaining the state information of the object. The editor recommends a learning skirt for learning C language/C [627, 012, 464]. Whether you are an expert or a novice, want to change careers or want to join the industry, you can learn about it and learn together! There are development tools inside the skirt, and a lot of useful information and technical information are shared!

Question 3: What is object-oriented (OOP)?

Answer: Object-oriented is a method and idea for understanding and abstracting the real world. It is an idea that solves problems by converting demand elements into objects.

Question 4: What is polymorphism?

Answer: Polymorphism means that the same operation, function, or process can act on multiple types of objects and obtain different results. Different objects can produce different results when receiving the same message. This phenomenon is called polymorphism.

Question 5: Do you understand design patterns? Can you give me a simple example?

Answer: Design pattern (Design pattern) is a set of classified and cataloged summary of code design experience that is used repeatedly, known to most people.

For example, the singleton mode ensures that a class has only one instance and provides a global access point to access it.

Applies to: when the class can have only one instance and customers can access it from a well-known access point; when this single instance should be extensible through subclassing, and customers should not need to change the code When an extended instance can be used.

For example, the factory pattern defines an interface for creating objects and lets subclasses decide which class to instantiate. Factory Method causes the instantiation of a class to be deferred to its subclasses.

Applies to: when a class does not know the class of the object it must create; when a class wants its subclass to specify the object it creates; when the class will create the object When responsibility is delegated to one of multiple helper subclasses, and you want to localize the information about which helper subclass is the delegate.

Question 6: Have you ever used the STL library? What are the common STL containers? Which algorithms have been used?

Answer: STL includes two parts: container and algorithm. (It is also important to combine the two iterators)

Container, which is where data is stored. Such as array, etc.

In STL, containers are divided into two categories: sequential containers and associative containers.

Serial container, the elements in it are not necessarily in order, but they can all be sorted. Such as: vector, list, deque, stack, queue, heap, priority_queue, slist;

Associative container, the internal structure is basically a balanced binary tree. The so-called association means that each element has a key value and a real value, and the elements are stored according to certain rules. Such as: RB-tree, set, map, multiset, multimap, hashtable, hash_set, hash_map, hash_multiset, hash_multimap.

Choose one of each below as an explanation.

Vector: It is a container that dynamically allocates storage space. Different from array in C, the space allocated by array is static and cannot be changed after allocation, while vector will automatically reallocate (expand) the space.

set: Its internal elements will be automatically sorted according to the key value of the element. Different from map, its key values ​​are real values, and map can have different key values ​​and real values ​​at the same time.

Algorithms, such as sorting, copying... and container-specific algorithms. This point does not need to be introduced too much, mainly depends on the content of the iterator below.

Iterator is the essence of STL. We describe it like this: Iterator provides a way to access the various elements contained in a container in sequence without exposing the internal structure of the container. It separates the container and the algorithm so that they can be designed independently.

Question 7: Will the data structure be known? What are the main ones used in the project development process?

Answer: Arrays, linked lists, and trees (less often) are mainly used in data structures, and the ideas of stacks and queues are also used.

Question 8: Do you know const? Explain its function.

Answer:

1.const modifies the member variables of the class, indicating member constants and cannot be modified.

2. The const modified function promises not to modify the data members in the class within this function, and not to call other non-const member functions.

3. If const constitutes function overloading, const objects can only call const functions, and non-const objects call non-const functions first.

4.const functions can only call const functions. Non-const functions can call const functions.

5. Const member functions defined outside the class require const modifiers at both the definition and declaration.

Question 9: When are the static variables of the class initialized? When are the static variables of a function initialized?

Answer: The static member variables of the class already exist before the class is instantiated, and memory is allocated. The static variables of a function are initialized when this function is executed.

Question 10: What is the difference between heap and stack? Heap and stack life cycle?

Answer:

1. Differences in stack space allocation:

1. Stack (operating system): automatically allocated and released by the operating system to store function parameter values ​​and local variables value etc. Its operation method is similar to the stack in the data structure;

2. Heap (operating system): It is generally allocated and released by the programmer. If the programmer does not release it, it may be recycled by the OS when the program ends. The allocation method is similar. in the linked list.

2. Differences in stack caching methods:

1. The stack uses the first-level cache. They are usually in the storage space when they are called and are released immediately after the call is completed;

2. The heap is stored in the second-level cache, and its life cycle is determined by the garbage collection algorithm of the virtual machine (it does not mean that it can be recycled once it becomes an orphan object). Therefore, the speed of calling these objects is relatively low.

3. Differences in stack data structures:

Heap (data structure): The heap can be regarded as a tree, such as: heap sort;

Stack (data structure) ): A first-in-last-out data structure.

Question 11: Explain encapsulation, inheritance and polymorphism?

Answer:

1. Encapsulation:

Encapsulation is the first step in realizing object-oriented programming. Encapsulation is to collect data or functions in units. (We call them classes).

The meaning of encapsulation is to protect or prevent code (data) from being inadvertently destroyed by us.

2. Inheritance:

Inheritance mainly realizes code reuse and saves development time.

Subclasses can inherit some things from the parent class.

3. Polymorphism

Polymorphism: The same operation acts on different objects and can have different interpretations and produce different execution results. At runtime, you can call methods in a derived class through a pointer to the base class.

Question 12: What is the difference between pointers and references?

Answer:

  1. The pointer is a variable, but this variable stores an address, pointing to a storage unit in the memory; and the reference is just an alias;

  2. There is no need to dereference (*) when using references, pointers need to be dereferenced;

  3. References can only be initialized once when defined, and are immutable thereafter. ;The pointer is variable;

  4. The reference does not have const, the pointer has const;

  5. The reference cannot be null, the pointer can be null;

  6. "sizeof reference" gets the size of the variable (object) pointed to, while "sizeof pointer" gets the size of the pointer itself;

  7. The meaning of the increment () operation of pointers and references is different;

  8. Pointers can have multiple levels, but references can only be one level (int **p; is legal and int &&a is Illegal)

9. From the perspective of memory allocation: the program allocates a memory area for pointer variables, while references do not need to allocate a memory area.

Question 13: What is a memory leak? What methods do you have in the face of memory leaks and pointer out-of-bounds? What methods do you usually use to avoid and reduce these types of errors?

Answer: The space dynamically opened using the dynamic storage allocation function is not released after use. As a result, the memory unit is always occupied, which is a memory leak.

Remember the length of the pointer when using it.

You must make sure it is free when mallocing.

When assigning a value to a pointer, you should pay attention to whether the assigned pointer needs to be released.

It is best not to use dynamically allocated memory pointers. Assign again.

Question 14: What are the commonly used sorting algorithms? Briefly describe the advantages and disadvantages of several sorting algorithms?

Answer: Select, bubble, fast, **, Hill, merge, stack sort, etc.

1. Quick sort: It is an improvement of bubble sort.

Advantages: fast, less data movement

Disadvantages: insufficient stability

2. Merge: divide-and-conquer sorting, a stable sorting algorithm, generally used for overall order, but a locally ordered sequence.

Advantages: High efficiency O(n), stable

Disadvantages: Comparative memory usage

Question 15: What is the difference between new and malloc?

Answer:

1. malloc and free are standard library functions of C/C language, and new/delete are C operators. They can both be used to apply for dynamic memory and release memory.

2. For objects of non-internal data types, maloc/free alone cannot meet the requirements of dynamic objects. The object must automatically execute the constructor when it is created, and the object must automatically execute the destructor before it dies.

3. Since malloc/free is a library function rather than an operator, it is not within the control authority of the compiler. The task of executing constructors and destructors cannot be imposed on malloc/free. Therefore, C language needs an operator new that can complete dynamic memory allocation and initialization work, and an operator delete that can complete the work of cleaning up and releasing memory. Note that new/delete are not library functions.

4. C programs often call C functions, but C programs can only use malloc/free to manage dynamic memory.

5. New can be considered as the execution of malloc plus constructor. The pointer from new directly carries type information. Malloc returns void pointers.

Question 16: What is the difference between TCP and UDP communication? What is IOCP?

Answer:

1.TCP is connection-oriented, UDP is connection-less

2.TCP is guaranteed, UDP transmission is not guaranteed

3 .TCP is inefficient, but UDP is highly efficient

4.TCP is based on streams, and UDP is based on data packets

5.TCP transmits important data, and UDP transmits unimportant data

IOCP's full name is I/O Completion Port, which is translated into Chinese as I/O completion port.

IOCP is an asynchronous I/O API that can efficiently notify applications of I/O events.

Unlike using select() or other asynchronous methods, a socket [socket] is associated with a completion port, and then normal Winsock operations can continue. However, when an event occurs, the completion port will be added to a queue by the operating system. The application can then query the core layer for this completion port.

Question 17: What is the difference between synchronous IO and asynchronous IO?

Answer:

A. Synchronization

The so-called synchronization means that when a function call is issued, the call will not return until the result is obtained.

According to this definition, in fact, most functions are called synchronously (such as sin isdigit, etc.).

But generally speaking, when we talk about synchronous and asynchronous, we specifically refer to tasks that require the cooperation of other components or require a certain amount of time to complete.

The most common example is SendMessage.

This function sends a message to a certain window. This function does not return until the other party has processed the message.

After the other party has finished processing, this function returns the value returned by the message processing function to the caller.

B. Asynchronous

The concept of asynchronous is opposite to synchronization.

When an asynchronous procedure call is issued, the caller will not get the result immediately.

The component that actually handles this call is to notify the caller through status and notification after the call is issued, or process the call through a callback function.

Question 18: Explain static functions and static variables in C?

Answer:

(1) Class static data members are created and initialized at compile time: they exist before any object of this class is created, they do not belong to any object, and they are not static class member variables. It belongs to the object. There is only one copy of static data members of a class, which is shared by all objects of this class.

(2) Class static member functions belong to the entire class, not to a certain object, and are shared by all objects of the class.

1. Static member variables realize information sharing between similar objects.

2. Static members are stored outside the class, and the class size is not included.

3. The static member is a global variable belonging to the class in the namespace and is stored in the rw segment of the data area.

4. Static members can only be initialized outside the class.

5. It can be accessed through the class name (also when no object is generated), or through the object.

1. The significance of static member functions does not lie in information sharing and data communication, but in managing static data members and completing the encapsulation of static data members.

2. Static member functions can only access static data members. Reason: For non-static member functions, the this pointer is passed in as a parameter when called. Static member functions belong to classes, not objects, and do not have this pointers.

Question 19: Tell me about your understanding of memory?

Answer:

1. Stack - automatically allocated and released by the compiler

2. Heap - generally allocated and released by the programmer. If the programmer does not release it, when the program ends May be recycled by the OS

3. Global area (static area), global variables and static variables are stored together. Initialized global variables and static variables are in the same area, and uninitialized global variables and uninitialized variables are stored in the same area. The initialized static variables are in another adjacent area. - Release when the program ends

4. There is also a special place for constants. - The

5 program code area is released when the program ends, storing binary codes.

Variables defined in the function body are usually on the stack, and those allocated by functions such as malloc, calloc, realloc, etc. that allocate memory are on the heap. Global variables are defined outside the body of all functions. After adding the static modifier, they are stored in the global area (static area) no matter where they are. The static variables defined outside the body of all functions are valid in the file and cannot be externed to other files. Use, static defined in a function body means that it is only valid within the function body. In addition, strings such as "adgfdf" in the function are stored in the constant area.

Related articles:

Share 125 basic C# interview questions and answers

Related videos:

Detailed video tutorial on interview questions that sweeps the PHP workplace

The above is the detailed content of How many of these 19 C/C+ interview questions can you answer correctly? - Personal article Sifu. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
如何使用C#编写时间序列预测算法如何使用C#编写时间序列预测算法Sep 19, 2023 pm 02:33 PM

如何使用C#编写时间序列预测算法时间序列预测是一种通过分析过去的数据来预测未来数据趋势的方法。它在很多领域,如金融、销售和天气预报中有广泛的应用。在本文中,我们将介绍如何使用C#编写时间序列预测算法,并附上具体的代码示例。数据准备在进行时间序列预测之前,首先需要准备好数据。一般来说,时间序列数据应该具有足够的长度,并且是按照时间顺序排列的。你可以从数据库或者

如何使用Redis和C#开发分布式事务功能如何使用Redis和C#开发分布式事务功能Sep 21, 2023 pm 02:55 PM

如何使用Redis和C#开发分布式事务功能引言分布式系统的开发中,事务处理是一项非常重要的功能。事务处理能够保证在分布式系统中的一系列操作要么全部成功,要么全部回滚。Redis是一种高性能的键值存储数据库,而C#是一种广泛应用于开发分布式系统的编程语言。本文将介绍如何使用Redis和C#来实现分布式事务功能,并提供具体代码示例。I.Redis事务Redis

如何实现C#中的人脸识别算法如何实现C#中的人脸识别算法Sep 19, 2023 am 08:57 AM

如何实现C#中的人脸识别算法人脸识别算法是计算机视觉领域中的一个重要研究方向,它可以用于识别和验证人脸,广泛应用于安全监控、人脸支付、人脸解锁等领域。在本文中,我们将介绍如何使用C#来实现人脸识别算法,并提供具体的代码示例。实现人脸识别算法的第一步是获取图像数据。在C#中,我们可以使用EmguCV库(OpenCV的C#封装)来处理图像。首先,我们需要在项目

Redis在C#开发中的应用:如何实现高效的缓存更新Redis在C#开发中的应用:如何实现高效的缓存更新Jul 30, 2023 am 09:46 AM

Redis在C#开发中的应用:如何实现高效的缓存更新引言:在Web开发中,缓存是提高系统性能的常用手段之一。而Redis作为一款高性能的Key-Value存储系统,能够提供快速的缓存操作,为我们的应用带来了不少便利。本文将介绍如何在C#开发中使用Redis,实现高效的缓存更新。Redis的安装与配置在开始之前,我们需要先安装Redis并进行相应的配置。你可以

如何使用C#编写动态规划算法如何使用C#编写动态规划算法Sep 20, 2023 pm 04:03 PM

如何使用C#编写动态规划算法摘要:动态规划是求解最优化问题的一种常用算法,适用于多种场景。本文将介绍如何使用C#编写动态规划算法,并提供具体的代码示例。一、什么是动态规划算法动态规划(DynamicProgramming,简称DP)是一种用来求解具有重叠子问题和最优子结构性质的问题的算法思想。动态规划将问题分解成若干个子问题来求解,通过记录每个子问题的解,

C#开发中如何处理跨域请求和安全性问题C#开发中如何处理跨域请求和安全性问题Oct 08, 2023 pm 09:21 PM

C#开发中如何处理跨域请求和安全性问题在现代的网络应用开发中,跨域请求和安全性问题是开发人员经常面临的挑战。为了提供更好的用户体验和功能,应用程序经常需要与其他域或服务器进行交互。然而,浏览器的同源策略导致了这些跨域请求被阻止,因此需要采取一些措施来处理跨域请求。同时,为了保证数据的安全性,开发人员还需要考虑一些安全性问题。本文将探讨C#开发中如何处理跨域请

如何实现C#中的遗传算法如何实现C#中的遗传算法Sep 19, 2023 pm 01:07 PM

如何在C#中实现遗传算法引言:遗传算法是一种模拟自然选择和基因遗传机制的优化算法,其主要思想是通过模拟生物进化的过程来搜索最优解。在计算机科学领域,遗传算法被广泛应用于优化问题的解决,例如机器学习、参数优化、组合优化等。本文将介绍如何在C#中实现遗传算法,并提供具体的代码示例。一、遗传算法的基本原理遗传算法通过使用编码表示解空间中的候选解,并利用选择、交叉和

如何实现C#中的图像压缩算法如何实现C#中的图像压缩算法Sep 19, 2023 pm 02:12 PM

如何实现C#中的图像压缩算法摘要:图像压缩是图像处理领域中的一个重要研究方向,本文将介绍在C#中实现图像压缩的算法,并给出相应的代码示例。引言:随着数字图像的广泛应用,图像压缩成为了图像处理中的重要环节。压缩能够减小存储空间和传输带宽,并能提高图像处理的效率。在C#语言中,我们可以通过使用各种图像压缩算法来实现对图像的压缩。本文将介绍两种常见的图像压缩算法:

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
2 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function