-
Couldn't load subscription status.
- Fork 20
Rumeet Goradia - Assignment 7 #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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. | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The simple answer to this question is neither. C doesn’t always evaluate left-to-right or right-to-left. Generally, function calls are evaluated first, followed by complex expressions and then simple expressions. |
||
| 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. | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. right! some more important things to note: |
||
| 4. 1. char * --> "abc" is a string, which is basically a char pointer | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. perfect! 💯 |
||
| 2. invalid --> substracting a char from a string is not allowed in C | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is actually valid! "xyz" is just an array of characters, so the "xyz"[1] is just accessing "y". Then you just subtract 'y' from it to get 0. This is because, if you can recall, a char is just a value mapped to a character! |
||
| 3. invalid --> cannot compare char to int | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is perfectly valid! '\0' is just a NULL terminator and by definition, NULL is equal to 0. So this would evaluate as true, which is 1 in C. |
||
| 4. 10 --> points to the first value of "a" | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. perfect! |
||
| 5. p-2 --> gives address number of a[0] | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. right, but we're looking for the data type, which is |
||
| 6. 12 --> gives value of a[2] | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perfect! |
||
| 7. int** --> stores memory address of a memory address of an int | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice job! |
||
| 8. char* --> advances memory location, then gives value of pointer of pointer, which is pointer | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes! |
||
| 9. int * --> gives memory location of int | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. pretty much right! You should have also given the parameter types (which would remain unchanged), but you got the gist of it correctly! |
||
| 10. int --> sizeof gives integer value | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you're right about the type, but you should have given us the standard size which is 8! |
||
|
|
||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great job overall! |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| /*Rumeet Goradia - String Reversal*/ | ||
| #include<stdio.h> | ||
| #include<string.h> | ||
|
|
||
| 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; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.