C++ 是一种通用编程语言,如今广泛用于竞争性编程。它具有命令式、面向对象和通用编程功能。 C++ 可以在很多平台上运行,比如 Windows、Linux、Unix、Mac 等。
Go 是一种过程式编程语言。它由 Google 的 Robert Griesemer、Rob Pike 和 Ken Thompson 于 2007 年开发,但于 2009 年作为开源编程语言推出。程序是通过使用包来组装的,用于有效管理依赖关系。该语言还支持采用类似于动态语言的模式的环境。
以下是 Golang 和 C++ 语言之间的一些差异:
Go |
C++ |
---|---|
Go is a procedural and concurrent programming language. | C++ is an object-oriented programming language. |
Go does not contain classes with constructors and deconstructors. | C++ does contain classes with constructors and deconstructors. |
Go language provides automatic garbage collection for allocating memory. | C++ language does not provide automatic garbage collection for allocating memory. |
Go language contains pointers, but does not contain arithmetic pointer. | C++ language contains both pointers as well as arithmetic pointers. |
In Go language, map is passed by reference. | In C++, map is passed by value. |
It does not use header files. Instead of header file, go use packages. It uses import to import external packages. | It contain header file and does not contain package. |
It does not support implicit type conversion. | It support implicit type conversion. |
It does not support function overloading and also does not support user defined operators. | It support function overloading and also support user defined operators. |
It does not support const or volatile qualifiers. | It supports const and volatile qualifiers. |
It provides nil for invalid pointers. | It provides NULL or 0 or nullptr for invalid pointers |
Go use panic and recover for resolving error. | C++ use try, catch, and throw for resolving error. |
It does not have while or do-while statements. But for loop can be used like a while loop. | It have while or do-while statements. |
It is more strong typed as comparison to C++ language. | It is less strong typed as compare to Go language. |
Go contains goroutines and channel. | C++ has threads. |
Go does not support inheritance. But it provides an alternative in the form of Embedding. | C++ supports inheritance. |
想要从精选的视频和练习题中学习,请查看C++ 基础课程,从基础到高级 C++ 和C++ STL 课程,了解基础加 STL。要完成从学习语言到 DS Algo 等的准备工作,请参阅完整的面试准备课程。