Chinaunix首页 | 论坛 | 博客
  • 博客访问: 260200
  • 博文数量: 84
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 927
  • 用 户 组: 普通用户
  • 注册时间: 2015-03-06 23:00
个人简介

growing

文章分类

全部博文(84)

文章存档

2017年(6)

2016年(61)

2015年(17)

我的朋友

分类: C/C++

2015-09-18 18:08:11

1.

点击(此处)折叠或打开

  1. #include <stdio.h>
  2. struct Test
  3. {
  4.     int Num;
  5.     char *pcName;
  6.     short sDate;
  7.     char cha[2];
  8.     short sBa[4];
  9. }*p;
  10. //假设p 的值为0x100000。 如下表表达式的值分别为多少?
  11. int main()
  12. {
  13.     struct Test test;
  14.     p = &test;
  15.     printf("%#p\n", p);
  16.     printf("%#p\n", p + 0x1);
  17.     printf("%#p\n", (unsigned long)p + 0x1);
  18.     printf("%#p\n", (unsigned int*)p + 0x1);
  19.     return 0;
  20. }

    点击(此处)折叠或打开

    1. #include <stdio.h>

    2. int main()

      点击(此处)折叠或打开

      1. #include <stdio.h>

      2. void print(int *p, int len)
      3. {
      4.     int i = 0;
      5.     for (i = 0; i < len; i++)
      6.     {
      7.         printf("%d ", p[i]);
      8.     }
      9. }
      10. int main()
      11. {
      12.     int arr[3][4] = {0,1,2,3,4,5,6,7,8,9,10,11};
      13.     print(&arr[0][0], sizeof(arr) / sizeof(int));
      14.     //int i = 0;
      15.     //int j = 0;
      16.     //for (i = 0; i < 3; i++)
      17.     //{
      18.     //    for (j = 0; j < 4; j++)
      19.     //    {
      20.     //        printf("&arr[%d][%d] = %p\n", i, j, &arr[i][j]);
      21.     //    }
      22.     //}
      23.     return 0;
      24. }



      25. //#include <stdio.h>
      26. //int main(int argc, char * argv[])
      27. //{
      28. //    int a[3][2] = { (0, 1), (2, 3), (4, 5) };
      29. //    int a1[3][2] = { 0 };
      30. //    int a2[3][2] = { 0,1,2,3};
      31. //    int a1[3][2] = { { 0, 1 }, { 2, 3 }, { 4, 5 } };
      32. //
      33. //
      34. //    int *p;
      35. //    p = a[0];
      36. //    printf("%d", p[0]);
      37. //    system("pause");
      38. //    return 0;
      39. //}
      40. //
      41. //#include <stdio.h>
      42. //
      43. //int main()
      44. //{
      45. //    int a[5][5];//0x00000000
      46. //    int(*p)[4];
      47. //    p = (int (*)[4])a;
      48. //    //&a[4][2]=== ((a+4)+2)
      49. //    printf("a_ptr=%#p,p_ptr=%#p\n", &a[4][2], &p[4][2]);
      50. //    //0x16 0x12
      51. //    //p[4][2] === *((p+4)+2)
      52. //    printf("%p,%d\n", &p[4][2] - &a[4][2], &p[4][2] - &a[4][2]);
      53. //    //-4
      54. //    //10000000 00000000 00000000 00000100
      55. //    //11111111 11111111 11111111 11111011
      56. //    //ff ff ff fc
      57. //    int i = -1;
      58. //    printf("%p\n", i);
      59. //    system("pause");
      60. //    return 0;
      61. //}
      62. //
      63. //

      64. /*#include <stdio.h>
      65. int main()
      66. {
      67.     int a[5] = { 1, 2, 3, 4, 5};
      68.     int i = 0;
      69.     int *q = &i;
      70.     int j = *(q + 1);
      71.     int *p = &j;

      72.     printf("%d\n", &a[2] - &a[4]);
      73.     system("pause");
      74.     return 0;
      75. }
      76. */


    3. {
    4.     int a[4] = { 1, 2, 3, 4 };
    5.     int *ptr1 = (int *)(&a + 1);
    6.     int *ptr2 = (int *)((int)a + 1);
    7.     printf("%x,%x", ptr1[-1], *ptr2);//ptr1[-1] === *(ptr+(-1))
    8.     return 0;
    9. }

阅读(1141) | 评论(0) | 转发(0) |
0

上一篇:C练习小题

下一篇:[c]猜拳游戏

给主人留下些什么吧!~~