zoukankan      html  css  js  c++  java
  • c指针点滴1

     1 #include <stdio.h>
     2 #include <stdlib.h>
     3 
     4 
     5 void main()
     6 {
     7     int num = 10;
     8     int *p = &num;//&num是一个地址 一个常量
     9     //p是一个指针变量 可以存储一个地址 一个变量
    10 }
    11 void main3()
    12 {
    13     int *p1;
    14     char *p2;
    15     double *p3;
    16     printf("%d,%d,%d",sizeof(p1),sizeof(p2),sizeof(p3));//指针只是一个地址 大小是固定的 就是四个字节
    17 }
     1 #include <stdio.h>
     2 #include <stdlib.h>
     3 
     4 void main1()
     5 {
     6     int num = 100;
     7     int *p;//error 使用了未初始化的局部变量
     8     //在一些c++编译器里面 不检查变量的初始化,指针使用之前必须初始化
     9     //p = num;//相对于把100的地址给了p  可以编译不能运行
    10     p = &num;
    11     printf("%d",*p);
    12     printf("%x",&p);
    13 
    14 
    15     getchar();
    16 }
     1 #include <stdio.h>
     2 #include <stdlib.h>
     3 
     4 void main()
     5 {
     6     int *p = NULL;//指针开始最好都初始化为空
     7     if(p == NULL)
     8     {
     9         printf("妹子p现在是单身 可以疯狂的进攻");
    10     }else
    11     {
    12         printf("妹子p不是单身 请慎重考虑");
    13     }
    14     //printf("%d",*p);//不合法0x000000操作系统使用 不可以随便玩 
    15 
    16     getchar();
    17 }
     1 #include <stdio.h>
     2 #include <stdlib.h>
     3 
     4 void main4()
     5 {
     6     double a = 1,b=2,c=3;//double8个字节
     7     //double *pa,pb,pc;//指针四个字节 pa是指针 
     8     double *pa,*pb,*pc;
     9     printf("%d%d%d",sizeof(pa),sizeof(pb),sizeof(pc));
    10 }

    2016-10-1

  • 相关阅读:
    Thinkphp5+PHPExcel实现批量上传表格数据
    使用ECharts画K线图
    ThinkPHP5+Layui实现图片上传加预览
    SVN使用教程总结
    JS内置对象方法
    头像上传【实用php】
    Sublime Text 3 快捷键总结
    javascript--基础 三元表达式
    javascript---运算符、表达式、递增、比较运算符、逻辑运算符
    导入dmp的sql语句
  • 原文地址:https://www.cnblogs.com/lanjianhappy/p/5960022.html
Copyright © 2011-2022 走看看