Monday, December 31, 2012

C/C++ Note

C/C++ Note
The difference between C and C++:
1. The declaration meaning: int func();
2. Initialization and Clean up
3. function overloading
4. C++ access control
5. C++'s reference

Can't directly inititialize class variable in the class body.
class point{
    int x=0;//Error!
}

1、函数调用时,是将实参的“值“压栈,等进入函数后将该值出栈交给形参。此时形参为char *pstr,实参为char *rstr,实际上将指针值交给形参,所以对于形参的修改(指针值),对实参没有任何关系。
2、指针定义时要初始化,一般设为NULL,或者直接指向一块地址,避免出现野指针。
3、指针用完后一定要释放指向的空间,避免出现内存泄漏;并且将其设置为NULL,避免出现野指针。


C operators are all available in C++, but C++ has operators
that are not found in C, such as the scope resolution operator ::.

The C++ standard I/O library is iostream
or iostream.h. The file name without the .h extension is the official ANSI standard name.
Officially, the ANSI standard libraries that are taken from C libraries are c followed by
their names without the .h extension. The ANSI C standard library stdio.h can be used as
the ANSI C++ library cstdio.

The simple native types in C++ are bool, int, double, char, and wchar_t. These types
have a set of values and representation that is tied to the underlying machine architecture
on which the compiler is running. Both the bool and the wchar_t types are new to
C++ and are not in C and early C++ systems. The bool type provides a native boolean
type, and wchar_t provides a wide character type, used for representing character sets
requiring more than the standard 255 characters.

C++ also has the sizeof operator, which is used to determine the number of bytes a
particular object or type requires for storage.

No comments:

Post a Comment