第7章 指针【C语言课件】.pptVIP

  • 1
  • 0
  • 约2.73万字
  • 约 88页
  • 2019-04-30 发布于湖北
  • 举报
指 针 指针变量的声明和初始化 指针运算符 函数的传引用调用 对指针使用const 限定符 使用传引用调用的泡沫排序法 指针表达式和指针的算术运算 指针和数组的关系 指针数组 实例研究 指向函数的指针 实例研究 如果反复随机选中已经洗好的牌,洗牌算法可能会执行无数次。这种现象称为“无限延迟” (可通过优化算法解决“无限延迟”问题) 以顺乎自然的方式制定的算法有时存在诸如无限延迟等等的微妙的性能问题。应选择不存在无限延迟现象的算法 要发第一张牌就从数组中查找等于1的数组元素deck[row][column] 。这是用嵌套的for 循环完成的,for 循环中的变量row 从0变化到3、column 从0 变化到12。怎样表示发出的每一张牌呢?因为数组suit 已经预载入了四种花色, 所以通过打印字符串suit[row]可获得花色。同样,打印字符串face[column]可获得牌的面值。我们还打印出字符串“of” 。以正确的顺序打印这些信息可以打印出每一张牌,如打印出“King of Clubs” 、“Ace of Diamonds” 下面用自顶向下逐步求精的方法描述洗牌和发牌的算法 实例研究 算法的顶层是简单的,即 Shuffle and deal 52 cards 第一次求精得出的结果为: Initialize the suit array Initialize the face array Initialize the deck array Shuffle the deck(洗牌) Deal 52 cards(发牌) “洗牌”过程求精的结果为: For each of the 52 cards Place card number in randomly selected unoccupied slot of deck (把发牌序号插入到随机选出来的未选中过的牌中) 实例研究 “发牌”过程的求精结果为: For each of the 52 cards Find card number in deck array and print face and suit of card (在数组deck中查找发牌序号并打印出该张牌的面值和花色) 把上述两个求精过程合并起来就得到第二步求精的结果: Initialize the suit array Initialize the face array Initialize the deck array For each of the 52 cards Place card number in randomly selected unoccupied slot of deck For each of the 52 cards Find card number in deck array and print face and suit of card /* 试图修改指向常量数据的常量指针 */ # includestdio.h main() { int x = 5, y; const int * const ptr = x; *ptr = 7; ptr = y; return 0; } 编译输出: Compiling FIG7_13.C: Error FIG7_13.C8: Cannot modify a const object Error FIG7_13.C9: Cannot modify a const objiect Warning FIG7_13.C11:’ptr’ is assigned a value that is never used Warning FIG7_13.C11:’y’ is deci

文档评论(0)

1亿VIP精品文档

相关文档