From 434680650cfd0f300b7d2c4cc8823c64f865ee70 Mon Sep 17 00:00:00 2001 From: Christopher Liu Date: Sun, 10 Jul 2016 18:33:14 -0400 Subject: [PATCH] Assignment 7 --- assignment7.txt | 16 ++++++++++++++++ reverse.c | 21 +++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 assignment7.txt create mode 100644 reverse.c diff --git a/assignment7.txt b/assignment7.txt new file mode 100644 index 0000000..d6d8872 --- /dev/null +++ b/assignment7.txt @@ -0,0 +1,16 @@ +1. For an array {1, 2, 3, 4} + a. ++*p will get the variable located at *p then increment it. if *p is at index 0, new array would be {2, 2, 3, 4} with *p at index 0 + b. *p++ will increment p (move the index forward once), then get the value of it. If *p is at index 0, then the array will be {1,2,3,4} with *p at index 1 + c. *++p is equivalent to *p++ as the prefix ++ and * evaluate right to left. +2. No, it depends on the type of operator. +3. Pointers are used for functions that need to actually change their arguments or for returning an array of values +4.1 char[] +4.2 invalid +4.3 int 0 +4.4 int 10 +4.5 int * a +4.6 int 12 +4.7 int ** +4.8 char * +4.9 invalid +4.10 unsigned long int 8 \ No newline at end of file diff --git a/reverse.c b/reverse.c new file mode 100644 index 0000000..3a582a3 --- /dev/null +++ b/reverse.c @@ -0,0 +1,21 @@ +/*Christopher Liu */ +#include +#include + +int main() +{ + printf("String: "); + char string[100]; + fgets(string, 100, stdin); + + char *stringPtr = string; + char *end_stringPtr = &string[strlen(string)]; + + while (*stringPtr != *end_stringPtr) + { + printf("%c", *(--end_stringPtr)); + } + printf("\n"); + + return 0; +}