From 001588d469dd8ec88b3024398d5a3e19b81726ed Mon Sep 17 00:00:00 2001 From: elik723 Date: Mon, 11 Jul 2016 09:04:01 -0400 Subject: [PATCH] Assignment 7, totally on time --- assignment7.txt | 21 +++++++++++++++++++++ reverse.c | 25 +++++++++++++++++++++++++ 2 files changed, 46 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..6a7018c --- /dev/null +++ b/assignment7.txt @@ -0,0 +1,21 @@ +1. Explain the difference between ++*p, *p++ and *++p, if there is any. + ++*p increments the value that p is pointing to and stores that new value at p. *p++ + Stores the value of p, then moves the pointer. I don't know what the last one does. +2. Is the left to right or right to left order guaranteed for operator precedence? + Not neccesarily, it depends what operators are being used. If a postfix is being used + then i's right to left, but otherwise it is right to left. +3. What are the advantages of using pointers? + Although shockingly, mind-bogglingly annoying, pointers can be helpful and more efficient + when used with arrays for the purposes of returning arrays from functions or just + managing arrays in general. +4. + 4.1 "abc" char name[] + 4.2 "xyz"[1] - ’y’ ? + 4.3 ’\0’ == 0 0 + 4.4 *a 10 + 4.5 &a[0] int + 4.6 *p 12 + 4.7 &p int + 4.8 *++argv ? + 4.9 &main ? + 4.10 sizeof(str) int diff --git a/reverse.c b/reverse.c new file mode 100644 index 0000000..6bb19bb --- /dev/null +++ b/reverse.c @@ -0,0 +1,25 @@ +#include +#include + +void sReverse(char a[]) +{ + char *ptrStart = a; + char *ptrEnd = ptrStart + strlen(a) - 1; + int i; + for (i = 0; *ptrStart != *ptrEnd; i++) + { + printf("%c", *ptrEnd); + ptrEnd--; + } + printf("%c", a[0]); +} + +int main() +{ + printf("Enter a string. Through some shenanigans I don't understand, it should be reversed.\n"); + char word[100]; + fgets(word, sizeof(word), stdin); + sReverse(word); + return 0; +} +