//HelloWorld.cpp:Defines the entry point for the console application.//#include"stdafx.h"#include"string.h"
#include "iostream.h"
/** * in C, C + + language * Declaration: Declare pointer variable with *, declare variable or constant is not added *. * For example, parameters in function declarations, return value types, and so on. For example, the Declaration of a field in a class. * In the assignment statement: * Indicates the value. & Represents the address of the variable, that is, the pointer is taken. * * Class,struct,unit: Also follow the above principles. In addition, * when using pointers for variable access, method invocation, to use * * In the use of the instance of the variable, the method of invocation, to be used. * For example Persontest () method: * p is a pointer, *p is the instance to which P is pointing. * * Persontest () memory model in test: * pointer P Value *p, also known as instance * ___________ __________ ___________ * | | | name |-------> | Fang Jinuo | *name * | | ————— > | age:23 | |___________| * |___________| | Address | ______________________ * |__________|-------> | Bei Jing, Haid Dian | *address * |_____________________| */classperson{Private: Char*name; intAge ; Char*address; Public : Char*toString () {Char* ret=name; returnret; } voidSetage (intAge ) { This->age=Age ; } voidSetaddress (Char*address) { This->address=address; } voidSetName (Char*name) { This->name=name; }};voidpersontest () { person* p=NewPerson (); P->setaddress ("Bei Jing, Hai Dian");//assigning values in the form of pointers(*p). SetName ("Fang Jinuo");//assigning values in the same way as objects(*p). Setage ( at); printf ("Show info:\n%s\n", (*p). toString ());}voidswitchtest () {intA= at; intb=1; intC=0; CharOper='+'; Switch(oper) { Case '+': C=a+b; Case '-': C=a-b; Break; Case '*': C=a*b; Break; } printf ("C =%d%c%d =%d", A, Oper, b, c);}/** * Input and output of C language*/voidInput_output_test_c () {printf ("Hello world!\n"); printf ("Zhang San, wo Cao \ n"); intb; printf ("input Tow int number, pattern is D, d:\n"); scanf ("%d,%d", &a, &b); printf ("A is%d\n", a); printf ("B is%d\n", B); printf ("a+b=%d\n", A +b);}
/**
* C + + input and output
* Include iostream.h required before use
*/
void Input_output_test_cpp ()
{
<< out1 << out2 << out3 << out4 << Endl;
Endl represents EndLine, that is, line break
char * content=new char;
cout << "Plese input:" << Endl;
Cin>> content;
cout << content << Endl;
}
/**
* Namespace
* C language is not supported.
* C + + support.
*
*/
Namespace MyNS
{
void Namespacetest () {
cout << "MyNS namespace invoked" << Endl;
}
}
void Namespacetest () {
cout << "Current namespace invoked" << Endl;
}
int Main (intChar* args[]) {
Input_output_test_c ();
Persontest ();
Switchtest ();
Input_output_test_cpp ();
Namespacetest ();
Myns::namespacetest ();
return 0 ;}
C, C + +: references, pointers, instances, memory models, namespace