search

c++ basic knowledge

Oct 26, 2019 am 10:48 AM
c++basic knowledge

c++ basic knowledge

c Basics

C is an intermediate language developed by Bjarne Stroustrup at Bell in 1979 Design and development started in the laboratory. C further expands and improves the C language and is an object-oriented programming language. C runs on a variety of platforms, such as Windows, MAC operating systems, and various versions of UNIX. C language is a process-oriented language. On this basis, C adds object-oriented and generic programming mechanisms, so C is more suitable for the development of large and medium-sized programs. However, C does not sacrifice efficiency, and if you do not use advanced features, its efficiency is almost the same as that of the C language.

Recommended study: c manual tutorial

The following is a summary of the basic knowledge of c, I hope it will be helpful to you.

1. What are the basic data types in C?

Answer: 3 types: integer, floating point, and void.

2. There are several forms of integers. What are the differences between the various forms?

Answer: Integer types include arithmetic types of integers, characters and Boolean values, which are subdivided into 13 forms according to modifiers. The main differences are reflected in the type name, length, and representation range.

3. What are the constants in C?

Answer: 6 types of constants: integer constants, floating point constants, character constants, string constants, escaped character constants, and address constants.

4. What are the differences between constants and variables?

Answer: (1) The value of a constant cannot be changed, but the value of a variable can be changed; (2) The constant must be initialized when it is defined, and the variable does not need to be initialized when it is defined; (3) The constant cannot be found The address can only be assigned to a constant pointer, and variables can be addressed; (4) Constants have higher compilation and execution efficiency;

5. What are the classifications of operators?

Answer: (1) According to the operands: unary operators, binary operators, ternary operators; (2) According to functions: arithmetic operators, relational operators, logical operations operator, bitwise operator, assignment operator, increment and decrement operator, arrow operator, conditional operator, sizeof operator, comma operator.

6. What is the difference between the pre-operation and the post-operation of self-increment and self-decrement?

Answer: The priority of the former increment and self-decrement operation is greater than the assignment operator (=), the priority of the latter increment and self-decrement operation is smaller than the assignment operator, and the expression after the latter increment and self-decrement operation is The value of the formula will not change.

7. What is the difference between the increment and decrement of pointers and variables?

Answer: The increment and decrement of a variable changes the value of the variable, and the increment and decrement of a pointer changes the address pointed by the pointer.

8. What are lvalues ​​and rvalues?

Answer: Variables are lvalues ​​and can be on the left side of assignment statements; numerical literals are rvalues ​​and cannot be assigned.

9. What are the initialization methods for variables?

Answer: 2 types: direct initialization; copy initialization. Direct initialization is more flexible and performs more efficiently.

10. What are the declaration and definition of variables?

Answer: The main purpose of variable declaration is to indicate the type and name of the variable; the main purpose of variable definition is to allocate storage space, when they are the same.

11. What kinds of scopes are there in C?

Answer: 3 types: global scope, local scope, statement scope.

12. What are the storage types of variables?

Answer: 4 types: automatic type, static type, register type, external type.

13. What is the difference between C and C?

Answer: C language is a structured programming language. It is process-oriented and considers the implementation process; C is object-oriented and considers the entire program model.

14. What is the difference between macro definition and operator?

Answer: Macro definition is one of the preprocessing commands of C. It is a replacement operation that does not perform calculations and expression solving, and does not occupy memory or compilation time.

15. What are the characteristics of virtual functions and pure virtual functions?

Answer: A virtual function must be a non-static member function of the base class, and its access permission can be protected or public; a pure virtual function is a subset of virtual functions, and a class containing a pure virtual function is Abstract class, it cannot generate objects.

16. How to use pure virtual functions?

Answer: Pure virtual functions are used to define meaningless implementations and are used for methods in abstract classes that need to be handed over to derived classes for concrete implementation.

17. What is a pointer?

Answer: A pointer is a variable used to store a memory address. It points to the address of a single object. In addition to the void pointer type, the data type of the pointer needs to be consistent with the data type of the variable pointing to the address. .

18. What is the difference between pointers to const objects and const pointers?

Answer: The value of the const pointer itself cannot be changed, but the pointer can be used to modify the value of the object it points to; the pointer to a const variable cannot modify the value of the const variable it points to, but the pointer itself Can be reassigned.

19. What is the difference between array pointer and pointer array?

Answer: An array pointer is a pointer variable, which points to an array; a pointer array is an array containing only pointer elements, and its elements can point to different objects of the same type.

20. What is a function pointer?

Answer: A function pointer is a pointer pointing to the storage space address of a function. You can assign a value to the function pointer and call the function through the function pointer.

21. What is the difference between reference and value passing?

Answer: Pass by value passes a copy of the value, and the function's operation on the formal parameter will not affect the value of the actual parameter; pass by reference passes the memory address of the reference object, and the function's operation on the formal parameter will not affect the value of the actual parameter. The operation will affect the value of the actual parameter, and the value of the actual parameter will change as the value of the formal parameter changes.

22. What is the difference between pointers and references?

Answer: (1) References do not need to be dereferenced, pointers need to be dereferenced; (2) References are initialized once when they are defined, and are immutable thereafter, while pointers are mutable; (3) References cannot be empty. , the pointer can be empty; (4) The program allocates a memory area for the pointer variable, but the reference does not need to allocate a memory area, so the pointer increment operation is the auto-increment of the pointer variable, and the reference auto-increment operation is the auto-increment of the variable value.

23. What is the difference between object-oriented and process-oriented?

Answer: Process-oriented is a process-centered programming idea, driven by algorithms; object-oriented is an object-centered programming idea, driven by messages. The composition of a process-oriented programming language: program = algorithm data; the composition of an object-oriented programming language: program = object message.

24. What are the characteristics of object-oriented?

Answer: There are three elements of object-facing: encapsulation, inheritance, and polymorphism. All objects in object-oriented can be classified into a class.

25. What is the difference between a class and a structure?

Answer: (1) The structure is stored in the stack, and the instantiation of the class can be stored in the stack or the heap; (2) The execution efficiency of the structure is higher than that of the class ; (3) Structures do not have destructors, but classes have destructors; (4) Structures cannot be inherited, but classes can.

26. How to access static members?

Answer: Static members can be called directly through the class name without creating an instance of the class. They can also be called through an instance of the class, but the bottom layer is still called through the class name, so this is not recommended. method of calling. Static methods of a class can only access static members of the class.

27. What is polymorphism?

Answer: Polymorphism is to assign subclass objects to parent class variables. Parent class variables show different characteristics during compilation and runtime.

28. How to implement polymorphism in C?

Answer: Polymorphism includes dynamic polymorphism, static polymorphism, function polymorphism and macro polymorphism. The polymorphism we often refer to refers to dynamic polymorphism, which is based on the inheritance mechanism and virtual polymorphism. Function is implemented.

29. Conversion between derived class and base class?

Answer: A derived class can always be converted to a reference type of a base class; conversion from a base class to a derived class requires the use of cast when it is safe to do so.

30. What is a virtual member and what is its role?

Answer: The function of virtual function is to realize dynamic binding. After the program finds the keyword virtual before the name of the virtual function, it will automatically treat it as dynamic binding, that is, dynamic selection when the program is running. Appropriate member functions.

31. Overview of C covering and hiding?

Answer: (1) Overwriting means that there is a function with the same function name and parameters in the subclass and the parent class, and the function of the parent class is a virtual function; (2) Hiding It means that there are functions with the same function name and different parameters in the subclass and the parent class. At this time, regardless of whether the parent class function is a virtual function, the parent class function will be hidden, or there are functions with the same function name and parameters. , at this time, the parent class function will be hidden only when the parent class function is not a virtual function.

32. What are deep copy and shallow copy?

Answer: If a class has resources, when the resources of this class are copied, it is called a deep copy; if the object has resources but the resources are not copied during the copy process, it is a shallow copy.

33. What is the copy constructor and when is it called?

Answer: The copy constructor is called by the compiler to complete the construction of other objects based on the same class. and initialization. There are three situations where the copy constructor will be used: (1) An object is passed into the function body by value; (2) An object is returned from the function by value; (3) An object needs to be passed through another object. initialization.

34. What is the type conversion constructor?

Answer: The constructor of a class has only one parameter. The parameter type is not the type of the class but other types. This constructor is called a type conversion constructor, which can be used to process The same data value in different domains.

35. Does C support functions with an uncertain number of parameters?

Answer: C can support functions with uncertain parameters through the hidden parameter mechanism.

36. What is an inline function?

Answer: Member functions declared or defined inside a class declaration are called inline functions. Loop statements and switch statements are not allowed within inline functions.

37. What is the difference between reference formal parameters and non-reference formal parameters?

Answer: The reference parameter is to pass the address of the parameter variable, and the value of the actual parameter can be modified by calling the function on the formal parameter.

38. What are the problems with using reference parameters?

Answer: When calling a reference parameter of non-const type, the actual parameter must not be of const type, and the two types should be consistent; when calling a formal parameter function with a const reference, if the actual parameter is not a When the variables or types do not match, the function will create an unnamed temporary variable to store the value of the actual parameter, and use this formal parameter as a reference to the temporary variable.

39. What is the difference between pointer parameters and reference parameters?

Answer: Pointer parameter means that the parameter of the function is a pointer. It will not affect the value of the actual parameter through function call like the reference parameter, but it will modify the object of the actual parameter after the call. It is recommended to use pointer parameters as little as possible in the program, as this will reduce the readability of the program.

40. What is a static function? How to use static functions?

Answer: A static function is a function modified with the static modifier. A static function does not have this pointer and can only access static variables. If the result of a function call in a class will not access or modify any object data members, it is better to declare such members as static member functions.

41. Function overloading and scope?

Answer: Function overloading refers to multiple functions with the same name but different parameter lists in the same scope.

42. How to implement type conversion of actual parameters when function overloading?

Answer: When matching function overloading, the matching is first achieved through standard conversion. If No, then use class type conversion to achieve matching.

43. What is a function template?

Answer: Function template technology refers to the use of template technology to define non-member functions of parameterized types, which enables programs to call the same function using different parameter types.

44. What is a class template?

Answer: Class templates are classes that use template technology to describe general data types that can manage other data types. Class template technology is often used to create container classes that contain other types (queues, linked lists, stacks, etc.).

45. What is generic programming?

Answer: Generic programming is writing code in a way that is independent of the implementation of a specific class, and providing a common implementation for different types.

46. How to implement generic programming in C?

Answer: The implementation of generic programming in C is achieved using template technology in C, mainly by designing function templates and class templates.

The above is the detailed content of c++ basic knowledge. 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
Developing with C# .NET: A Practical Guide and ExamplesDeveloping with C# .NET: A Practical Guide and ExamplesMay 12, 2025 am 12:16 AM

C# and .NET provide powerful features and an efficient development environment. 1) C# is a modern, object-oriented programming language that combines the power of C and the simplicity of Java. 2) The .NET framework is a platform for building and running applications, supporting multiple programming languages. 3) Classes and objects in C# are the core of object-oriented programming. Classes define data and behaviors, and objects are instances of classes. 4) The garbage collection mechanism of .NET automatically manages memory to simplify the work of developers. 5) C# and .NET provide powerful file operation functions, supporting synchronous and asynchronous programming. 6) Common errors can be solved through debugger, logging and exception handling. 7) Performance optimization and best practices include using StringBuild

C# .NET: Understanding the Microsoft .NET FrameworkC# .NET: Understanding the Microsoft .NET FrameworkMay 11, 2025 am 12:17 AM

.NETFramework is a cross-language, cross-platform development platform that provides a consistent programming model and a powerful runtime environment. 1) It consists of CLR and FCL, which manages memory and threads, and FCL provides pre-built functions. 2) Examples of usage include reading files and LINQ queries. 3) Common errors involve unhandled exceptions and memory leaks, and need to be resolved using debugging tools. 4) Performance optimization can be achieved through asynchronous programming and caching, and maintaining code readability and maintainability is the key.

The Longevity of C# .NET: Reasons for its Enduring PopularityThe Longevity of C# .NET: Reasons for its Enduring PopularityMay 10, 2025 am 12:12 AM

Reasons for C#.NET to remain lasting attractive include its excellent performance, rich ecosystem, strong community support and cross-platform development capabilities. 1) Excellent performance and is suitable for enterprise-level application and game development; 2) The .NET framework provides a wide range of class libraries and tools to support a variety of development fields; 3) It has an active developer community and rich learning resources; 4) .NETCore realizes cross-platform development and expands application scenarios.

Mastering C# .NET Design Patterns: From Singleton to Dependency InjectionMastering C# .NET Design Patterns: From Singleton to Dependency InjectionMay 09, 2025 am 12:15 AM

Design patterns in C#.NET include Singleton patterns and dependency injection. 1.Singleton mode ensures that there is only one instance of the class, which is suitable for scenarios where global access points are required, but attention should be paid to thread safety and abuse issues. 2. Dependency injection improves code flexibility and testability by injecting dependencies. It is often used for constructor injection, but it is necessary to avoid excessive use to increase complexity.

C# .NET in the Modern World: Applications and IndustriesC# .NET in the Modern World: Applications and IndustriesMay 08, 2025 am 12:08 AM

C#.NET is widely used in the modern world in the fields of game development, financial services, the Internet of Things and cloud computing. 1) In game development, use C# to program through the Unity engine. 2) In the field of financial services, C#.NET is used to develop high-performance trading systems and data analysis tools. 3) In terms of IoT and cloud computing, C#.NET provides support through Azure services to develop device control logic and data processing.

C# .NET Framework vs. .NET Core/5/6: What's the Difference?C# .NET Framework vs. .NET Core/5/6: What's the Difference?May 07, 2025 am 12:06 AM

.NETFrameworkisWindows-centric,while.NETCore/5/6supportscross-platformdevelopment.1).NETFramework,since2002,isidealforWindowsapplicationsbutlimitedincross-platformcapabilities.2).NETCore,from2016,anditsevolutions(.NET5/6)offerbetterperformance,cross-

The Community of C# .NET Developers: Resources and SupportThe Community of C# .NET Developers: Resources and SupportMay 06, 2025 am 12:11 AM

The C#.NET developer community provides rich resources and support, including: 1. Microsoft's official documents, 2. Community forums such as StackOverflow and Reddit, and 3. Open source projects on GitHub. These resources help developers improve their programming skills from basic learning to advanced applications.

The C# .NET Advantage: Features, Benefits, and Use CasesThe C# .NET Advantage: Features, Benefits, and Use CasesMay 05, 2025 am 12:01 AM

The advantages of C#.NET include: 1) Language features, such as asynchronous programming simplifies development; 2) Performance and reliability, improving efficiency through JIT compilation and garbage collection mechanisms; 3) Cross-platform support, .NETCore expands application scenarios; 4) A wide range of practical applications, with outstanding performance from the Web to desktop and game development.

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

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft