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

  • 相关阅读:
    学习php中的正则表达式,PHP正则表达式基础
    在新浪云SAE中使用smarty引擎模版
    随笔
    HTML 基础(二)
    HTML笔记(一)
    数据挖掘之异常检测
    DHCP协议
    基础的Linux命令(二)
    基础的linux命令(一)
    VMware虚拟机安装
  • 原文地址:https://www.cnblogs.com/lanjianhappy/p/5960022.html
Copyright © 2011-2022 走看看