{"id":6791,"date":"2025-02-01T00:02:56","date_gmt":"2025-02-01T08:02:56","guid":{"rendered":"https:\/\/c-for-dummies.com\/blog\/?p=6791"},"modified":"2025-02-09T21:10:08","modified_gmt":"2025-02-10T05:10:08","slug":"testing-your-pointer-prowess","status":"publish","type":"post","link":"https:\/\/c-for-dummies.com\/blog\/?p=6791","title":{"rendered":"Testing Your Pointer Prowess"},"content":{"rendered":"<h2>Difficulty: &#9733; &#9733; &#9733; &#9734;<\/h2>\n<p>Pointers can drive C programmers mad. In fact, I&#8217;d say that evidence of this notion is that the most experienced C programmers have an air of insanity about them. To join their club, try working this month&#8217;s Exercise.<br \/>\n<!--more--><br \/>\nTo start, consider the following program:<\/p>\n<h3><a href=\"https:\/\/github.com\/dangookin\/C-For-Dummies-Blog\/blob\/master\/2025_02_01-Exercise.c\" rel=\"noopener\" target=\"_blank\">2025_02_01-Exercise.c<\/a><\/h3>\n<pre class=\"screen\">\r\n#include &lt;stdio.h&gt;\r\n\r\nint main()\r\n{\r\n    char *a[] = { \"I\", \"good\", \"language\" };\r\n    char *b[] = { \"am\", \"C\", \"excellent\", \"an\" };\r\n    char *c[] = { \"a\", \"programmer\", \"very\" };\r\n\r\n    printf(\"%s %s %s %s %s %s %s\\n\",\r\n            a[0],\r\n            b[0],\r\n            c[0],\r\n            c[2],\r\n            a[1],\r\n            b[1],\r\n            c[1]\r\n          );\r\n\r\n    return 0;\r\n}<\/pre>\n<p>Three arrays contain various strings. These strings are used in a <em>printf()<\/em> statement, generating this output:<\/p>\n<p><code>I am a very good C programmer<\/code><\/p>\n<p>This output is rather easy to guess if you&#8217;ve been programming C a while. Just ignore the pointers and use array notation to output the string. But more words are available in the arrays than are output, which hints at this month&#8217;s challenge.<\/p>\n<p>Your goal is to output this string:<\/p>\n<p><code>I am an excellent C programmer<\/code><\/p>\n<p>Before you start coding, you must add another pointer variable, <code>**z<\/code>, declared as follows:<\/p>\n<p><code>char **z[] = { a, b, c };<\/code><\/p>\n<p>Using pointer variable <code>z<\/code> &mdash; and only pointer variable <code>z<\/code> &mdash; you are to modify the <em>printf()<\/em> statement so that it outputs the string, <code>\"I am an excellent C programmer\"<\/code>.<\/p>\n<p>Once you figure out how to get the first word out, the rest aren&#8217;t as big of an issue. But hopefully this challenge gets your brain to think about pointers and asterisks and parentheses and all of that.<\/p>\n<p><a href=\"https:\/\/c-for-dummies.com\/blog\/?p=6802\">Click here<\/a> to view my solution.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Can you handle a double pointer challenge? <a href=\"https:\/\/c-for-dummies.com\/blog\/?p=6791\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-6791","post","type-post","status-publish","format-standard","hentry","category-exercise"],"_links":{"self":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/6791","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6791"}],"version-history":[{"count":5,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/6791\/revisions"}],"predecessor-version":[{"id":6840,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/6791\/revisions\/6840"}],"wp:attachment":[{"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6791"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6791"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/c-for-dummies.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6791"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}