// HelloWorld.cpp : Defines the entry point for the console application.
// #include "stdafx.h"
#include "string.h"
#include "iostream.h" /**
* 在C、C++语言中
* 声名语句中: 声明指针变量用*,声明变量或者常量都不加*。
* 譬如函数声明中的参数,返回值类型等。例如类中的字段的声明。
* 在赋值语句中: * 表示取值。 &表示取变量的地址,也就是取指针。
*
* class,struct,unit: 也遵循上述原则。另外,
* 在使用指针进行变量的访问、方法的调用时,要使用 ->
* 在使用实例进行变量的方式、方法的调用时,要使用.
* 例如personTest()方法中:
* p是指针,*p就是p所指向的实例。
*
* personTest()测试中的内存模型:
* 指针p Value *p ,也可以称为实例
* ___________ __________ ___________
* | | | name |-------> |Fang JiNuo | *name
* | | —————> | age : 23 | |___________|
* |___________| | address | ______________________
* |__________|-------> | Bei Jing, Haid Dian | *address
* |_____________________|
*/
class Person
{
private:
char* name;
int age;
char* address;
public :
char* toString()
{
char* ret=name;
return ret;
}
void setAge(int age){
this->age=age;
}
void setAddress(char* address){
this->address=address;
}
void setName(char* name){
this->name=name;
}
}; void personTest(){
Person * p=new Person();
p->setAddress("Bei Jing, Hai Dian"); // 采用指针的方式赋值
(*p).setName("Fang JiNuo"); // 采用对象的方式赋值
(*p).setAge();
printf("show info:\n%s\n", (*p).toString());
} void switchTest(){
int a=;
int b=;
int c=;
char oper='+';
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);
} /**
* C 语言的输入输出
*/
void input_Output_test_c(){
printf("Hello World!\n");
printf("zhang san, wo cao \n");
int a,b;
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++ 的输入输出
 * 使用前需要include iostream.h
 */
 void input_Output_test_cpp()

{

     // << out1 << out2 << out3 << out4 << endl;
     // endl 代表endline,也就是换行
     char * content=new char;
     cout << "plese input:" << endl;
     cin>> content;
     cout << content << endl;
  }


/**
 * namespace
 * C 语言不支持。
 * C++ 支持。
 *
 */
  namespace MyNS
  {
    void namespaceTest(){
      cout << "MyNS namespace invoked" << endl;
    }
  }


  void namespaceTest(){
    cout << "current namespace invoked" << endl;
  }

int main(int argc, char* args[])
{

// input_Output_test_c();
// personTest();
// switchTest();
// input_Output_test_cpp();
namespaceTest();
MyNS::namespaceTest();

    return ;
}

C、C++: 引用、指针、实例、内存模型、namespace的更多相关文章

  1. 栈 堆 stack heap 堆内存 栈内存 内存分配中的堆和栈 掌握堆内存的权柄就是返回的指针 栈是面向线程的而堆是面向进程的。 new/delete and malloc/ free 指针与内存模型

    小结: 1.栈内存 为什么快? Due to this nature, the process of storing and retrieving data from the stack is ver ...

  2. C++二级指针第二种内存模型(二维数组)

    C++二级指针第二种内存模型(二维数组) 二维数组 二维数组本质上是以数组作为数组元素的数组,即“数组的数组”. 定义 类型说明符 数组名[常量表达式][常量表达式] 例如: float a[3][4 ...

  3. C语言 二级指针内存模型混合实战

    //二级指针内存模型混合实战 #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <stdlib.h> #i ...

  4. C语言 二级指针内存模型③

    //二级指针内存模型③ #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <stdlib.h> #incl ...

  5. C语言 二级指针内存模型②

    //二级指针第二种内存模型 #define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include<stdlib.h> #incl ...

  6. C语言 二级指针内存模型①

    //二级指针第一种内存模型 #include<stdio.h> #include<stdlib.h> //说明:①:类似于int a[5]={0},数组名a是一维数组a中首元素 ...

  7. C++对象内存模型2 (虚函数,虚指针,虚函数表)

    从例子入手,考察如下带有虚函数的类的对象内存模型: class A { public: virtual void vfunc1(); virtual void vfunc2(); void func1 ...

  8. c语言二级指针内存模型

    第一种: 指针数组作为输入参数 char *myArray[] = {"aaaaaa", "ccccc", "bbbbbb", " ...

  9. C++二级指针第一种内存模型(指针数组)

    二级指针第一种内存模型(指针数组) 指针的输入特性:在主调函数里面分配内存,在被调用函数里面使用指针的输出特性:在被调用函数里面分配内存,主要是把运算结果甩出来 指针数组 在C语言和C++语言中,数组 ...

随机推荐

  1. iOS-掌握了时间就掌握了一切!

    Demo下载地址 一. NSDate相关知识 1.获取当前时间 [NSDate date]; 注意: 获取的当前时间是世界时间:比我们用的时间慢8个小时. 2.世界时间转化为本地时间 - (void) ...

  2. 关于一道PHP面试题的解法

    参照一个int型数组,如int[] a1=new int[]{10,9,10,20,15,3,9,8,7,1,1},编写一个方法,要求输出不重复,且降序的拼接字符串(连接字符用逗号),如上数组,输出的 ...

  3. Cloud Design Patterns: Prescriptive Architecture Guidance for Cloud Applications 云设计模式:云应用的规范架构指导

    1.Cache-aside Pattern 缓存模式 Load data on demand into a cache from a data store. This pattern can impr ...

  4. MacOS使用AMPPS环境

      下载(http://www.ampps.com/download)并安装AMPPS 基本配置:2.1选中所有扩展2.2 变更PHP版本为5.3 配置虚拟主机(Virtual Hosts) AMPP ...

  5. js树形控件—zTree使用总结

    0 zTree简介 树形控件的使用是应用开发过程中必不可少的.zTree 是一个依靠 jQuery 实现的多功能 “树插件”.优异的性能.灵活的配置.多种功能的组合是 zTree 最大优点. 0.0 ...

  6. siteMap与站点导航

    ASP.NET 站点导航主要由与站点地图数据源通信的站点地图提供程序以及公开站点地图提供程序的功能的类构成.ASP.NET 站点导航使您能够将到您所有页面的链接存储在一个中心位置,并通过包含一个用于读 ...

  7. Devexpress WPF Theme Editor 02

    Devexpress WPF Theme Editor 01 对于上次我们生成的主题 开始添加到我们的项目中. 运行Visual Studio和打开一个WPF解决方案,你想申请的主题. 添加的主题集会 ...

  8. 鼠标移到导航上面 当前的LI变色 处于当前的位置

    鼠标移到导航上面 当前的LI变色 处于当前的位置,广泛应用于当前导航. 点击这里查看效果 以下是源代码: <html> <head> <meta http-equiv=& ...

  9. css3 翻转和旋转的区别

    我以前一直以为旋转跟翻转一样,今日自己旋转了好久都发觉跟翻转差一点点,纠结了十几分钟才明白,只能怪自己的立体感太差了. css3中的transform中有旋转,放缩,倾斜,平移的功能,分别对应的属性是 ...

  10. 背水一战 Windows 10 (37) - 控件(弹出类): MessageDialog, ContentDialog

    [源码下载] 背水一战 Windows 10 (37) - 控件(弹出类): MessageDialog, ContentDialog 作者:webabcd 介绍背水一战 Windows 10 之 控 ...