Home PC Games Linux Windows Database Network Programming Server Mobile  
  Home \ Programming \ C ++ based foundation: the difference between C and C ++     - Hanoi problem Java Solution (Programming)

- Redmine Installation (Linux)

- Macro Analysis Performance: PHP Performance Analysis and Experiment (Programming)

- lack of SWAP space during installation of Oracle (Database)

- Linux kernel compilation, the configuration of the motor drive (Programming)

- Eight sorting algorithm implemented in Python (Programming)

- Open remote MySQL database connection managed under CentOS (Database)

- RPM package management under Linux (Linux)

- Oracle conditional select statements and looping statements (Database)

- Let Git variety of colors and custom log format output (Linux)

- MySQL simple operation notes under Linux (Database)

- Linux package manager - yum (Linux)

- Shell command line operation (Linux)

- How to choose the first programming language based on the life you want (Programming)

- How to use Evernote in the Linux command line (Linux)

- Linux environment variable settings methods and differences (Linux)

- Linux network monitoring tools ntopng installation (Linux)

- CentOS7 installation hardware monitoring for Zabbix enterprise applications (Server)

- Linux server alarms using Java (Server)

- Kali Linux resolve GPG error KEYEXPIRED 1425567400 (Linux)

  C ++ based foundation: the difference between C and C ++
  Add Date : 2018-11-21      
(1) C ++ Introduction and basic programming changes
The concept and use (2) namespace
(3) structure, union, enum different
(4) and Boolean operators alias
Overload (5) function, the default parameters, as well as inline dummy

1. Introduction and basic programming changes
Introduction 1.1 C language
1969, written in assembly language operating system, Thompson invented a language B language - Dennis Ritchie New B language on the basis of language B, later renamed C language
C language was born in 1972

Introduction 1.2 C ++ language
 On the basis of the C language, the Jani - Strauss special Loup (Bjarne Stroustrup) do a certain extension, named New C language, later renamed "C with Classes (with class C)", thought C ++ language operators, and finally renamed C ++, was born in 1983

1.3 related to historical events
(1) In 1983, C ++ language was born
(2) In 1985, CFront1.0 first C ++ compiler birth
(3) In 1987, GNU C ++ compiler
(4) In 1990, Borland C ++
 (5) In 1992, Microsoft C ++
 (6) In 1998, the first ISO C ++ standard birth
(Vc6.0 1998 was born)
 (7) In 2003, ISO standard for C ++ has been modified, C ++ 03 standard
(8) In 2011, the latest C ++ standard, C ++ 11 or C ++ 0x
 (Part of the compiler support)

Comparison 1.4 C ++ and C language
(1) C ++ and C language is a compiled language that is compiled to run only after, and some do not need to compile can be run directly, and is executed by an interpreter, this language is called scripting language
vi xxx.sh date; cal; ls -l;
 (2) C ++ and C languages are strongly typed language, all identifiers must have a data type
a; a = 10; // error
 (3) C ++ to C language provides compatible and optimized to provide more features
a. the language more concise style
b. more strict type checking
// Error
 int * pi = malloc (sizeof (int));
 c. support for object-oriented programming
d. Support Operator Overloading
1 + 1 = 2
A man + 10
 e. support for exception handling
f. support generic programming
double float ...

1.5 C ++ main purpose
(1) for game development
(2) for system and driver development

C ++ is no more the underlying C language, there is no JAVA / C # application level tend to be more
 Website Technology: javaWeb / .net / PHP

Write the first C ++ program

Basic 1.6 programming changes
Extension (1) file is changed
C language source file: xxx.c
 C ++ source files: .C / .cc / .cxx / .cpp (plus plus)

 C language header file: xxx.h
 C ++ header files: xxx.hpp / xxx.h

Change (2) header files
C language: #include
 In C ++: #include

Use C language header file:
#include remove .h, preceded by c
 vi /usr/include/c++/4.6/cstdio contained in the file or files stdio.h

Change (3) input and output
C language: scanf / printf function
In C ++: cin / cout objects

(4) changes in the compiler
C language: gcc / cc xxx.c
 In C ++: g ++ / c ++ xxx.cpp
 gcc / cc xxx.cpp -lstdc ++

g ++ / c ++ compiler options and gcc / cc as
-c compile only unconnected
-S Generated assembly file
-o Specify the output file name
-O Optimization

(5) namespace
using namespace std;
Use the standard namespace, class and standard library functions, etc. all on the std namespace

2. learn and use namespaces
 Introduced the concept of namespaces (namespace), mainly used to distinguish the same name as functions, variables, etc.

2.1 custom namespace
namespace namespace name
Variables, functions, etc.

 And format of the structure is very similar, but different keywords, and there is no semicolon, for defining the scope, not a separate data type

: N1, n2> represents the code between the lines n1 to n2 line right indent
: N1, n2
2.2 namespace way
(1) using namespace directives manner namespace
Such as:
using namespace std;

(2) the use of a scope qualifier
:: - Scope qualifier, the equivalent of "the"
Such as:
std :: cout << "Hello, everyone is really good";

(3) using the namespace declarations ways to use the namespace parts
Such as:
using std :: cout;
 using std :: endl;
 cout << "Hello, everyone is really good" << endl;

2.3 unnamed namespace
 If an identifier has not been placed in any namespace, the default is anonymous / anonymous namespace, you can use the following form to access identifier:

:: Unnamed namespace Member Name

2.4 Extended
(1) with a namespace of content can be written separately
(2) namespace function declarations and definitions to be separated, which is defined functions can be placed outside of the namespace
(3) can be nested namespace

3. The structure, union, enum different
3.1 structure is different
C language:
struct Student / * struct type name * / {...};
struct Student / * the left as a whole as a complete data type * / s;

 typedef struct Student
 {....} Student / * alias * /;

typedef struct
 {....} Student / * alias * /;

In C ++:
struct Student {...};
 [Struct] Student s;

(1) C ++ in the structure can omit the struct keyword when defining variables
(2) the internal structure of the C ++ function can be defined, and do not need to use the member variables within the function -> like

(1) In the C language, if a function parameter list is empty, that can accept any number of arguments of any type
(2) In C ++, if a function parameter list is empty, they said they did not accept any arguments

 Why s and s2 calls the same function and show a print out of the data content is not the same? ?
(Mentioned later)

3.2 differs from the union
(1) the definition of the joint variables can be omitted when the union keyword
(2) Joint Support Anonymous

Such as:
union un / * un joint type name * / {..};
 [Union] un u;

union {...}; anonymous union

3.3 enumeration differences
(1) enumerated type definition of variables may be omitted enum keyword
(2) the nature of the enumeration of the C language is an integer, integer assignment
C ++ enumeration is a separate data type, you can not use integer assignment
(Int type enumerated type range than large)

4. Boolean operators and aliases
4.1 Boolean
C language:
bool #include

In C ++:
bool type in C ++ is the basic data types, there are two values of type bool: true and false, it is essentially a 1 and 0
 bool type is essentially a single-byte integer, any of the basic data types can be implicitly converted to type bool

bool variable type definitions can be given as a parameter and return value types, of course, can also define a pointer type

4.2 Operator Alias
&& & | ||
 ^ Different XOR operator is true, the same false
 Discover manual string type in a variety of functions, try to use the various types of string functions
Such as:
string s;
 s.c_str ();
- When Linux Detailed time zone and common function of time (Linux)
- Linux + Apache + PHP + Oracle based environment to build (Server)
- How to monitor Linux system performance Nmon (Linux)
- ORA-00911 invalid character error Solution (Database)
- Security Configuration SQL Server 2000 database tutorial (Linux)
- Ordinary users how the Linux system shutdown (Linux)
- JITwatch installation under Linux (Linux)
- systemd Power Management (Linux)
- OpenNMS compile under Linux (Server)
- Java to achieve local fileCopy (Programming)
- Linux kernel likely and unlikely to resolve macro definitions (Linux)
- Talking about the shortcomings and deficiencies of the firewall (Linux)
- How to Install lightweight Budgie desktop on Ubuntu 14.04 (v8) (Linux)
- ORA-12537: TNS: connection closed error process (Database)
- The Linux-based security settings Ipchains Firewall (Linux)
- Gentoo: startx problem appears Failed to load module (Linux)
- CentOS card fails to start at boot progress bar certmonger solve (Linux)
- Git remote repository Explanation (Linux)
- Linux more efficient than select a model epoll (Linux)
- Install the Solaris 10 operating system environment over the network to sparc (Linux)
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.