From 4b1eab1a6fd62d217aa5fee9f81418ace36f6996 Mon Sep 17 00:00:00 2001 From: Rumeet Date: Sun, 10 Jul 2016 19:41:29 -0400 Subject: [PATCH 1/2] Rumeet Goradia - Reverse String --- reverse.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 reverse.c diff --git a/reverse.c b/reverse.c new file mode 100644 index 0000000..bab7abe --- /dev/null +++ b/reverse.c @@ -0,0 +1,23 @@ +/*Rumeet Goradia - String Reversal*/ +#include +#include + +void reversal (char *word) +{ + char *wordStart = word; + char *wordEnd = wordStart + strlen(word) - 2; + for(;wordEnd>=wordStart;wordEnd--) + { + printf("%c", *wordEnd); + } + printf("\n"); + return; +} +int main() +{ + char word[100]; + printf("Please input a string.\n"); + fgets(word, sizeof(word), stdin); + reversal(word); + return 0; +} From fedd7c30a6a87600d7e55c2611ff84d03f8ccbdb Mon Sep 17 00:00:00 2001 From: Rumeet Date: Sun, 10 Jul 2016 19:41:55 -0400 Subject: [PATCH 2/2] Rumeet Goradia - Assignment 7 Review Questions --- assignment7.txt | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 assignment7.txt diff --git a/assignment7.txt b/assignment7.txt new file mode 100644 index 0000000..6dc2cd1 --- /dev/null +++ b/assignment7.txt @@ -0,0 +1,15 @@ +Rumeet Goradia +1. ++*p increments the value that is stored in the memory location to which p points and stores that value. *p++ stores the value at the location to which p points and then advances p. (*p)++ stores the value at the location to which p points and then increments that value. +2. The left to right or right to left order for operator precedence is partially guaranteed for operator precedence. That is, many operators will be evaluated from left to right, but some operators operate from right to left. Therefore, in a line of code which contains operators from both of these groups, the expression will be evaulated in both directions. +3. Pointers allow for dynamic memory location, meaning that if we use them as arrays, the sizes of these arrays are not static. Pointers are also useful as parameters for functions. They can be used in functions that need to change their actual parameters; in other words, they can essentially be used to pass certain variables by reference instead of by value. Furthermore, without pointers, it is impossible to return an array of values. +4. 1. char * --> "abc" is a string, which is basically a char pointer + 2. invalid --> substracting a char from a string is not allowed in C + 3. invalid --> cannot compare char to int + 4. 10 --> points to the first value of "a" + 5. p-2 --> gives address number of a[0] + 6. 12 --> gives value of a[2] + 7. int** --> stores memory address of a memory address of an int + 8. char* --> advances memory location, then gives value of pointer of pointer, which is pointer + 9. int * --> gives memory location of int + 10. int --> sizeof gives integer value +