- 
                Notifications
    You must be signed in to change notification settings 
- Fork 20
Assignment complete #20
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,19 @@ | ||
| Clarke Littlejohn | ||
|  | ||
| 1) if i recall correctly ++*P moves the pointer then gets the values, *p++ get the value in the point the increments it | ||
| and *++p is not an apoerator that works. | ||
|  | ||
| 2) I am confused by what this si asking it will go by what it is prendence so to will go from right to left or left to right based on the highest order | ||
| 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) you are working directly with the value so it is always modifing the number. | ||
| 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. Pointers are more efficient in handling arrays and data tables | ||
|  | ||
| 4.1)string/char array/ | ||
| 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. close! we're looking for the specific data type, so it's  | ||
| .2)invalid | ||
| 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 | ||
| 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)pointer this gets the address of the array | ||
| 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 answer is 10 because it's just pointing to the first element of the array! | ||
| .5)address this gets the address | ||
| 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. 
 | ||
| .6)int this derefences the 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. right! but you need to evaluate the integer expression. Since a is a pointer to the first element of the array, the increment by 2 would move the pointer two spots over to 12. so 12 is the answer. | ||
| .7)pointer address p is pointer and ampersand gets the address | ||
| 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. 
 | ||
| .8) this seems like incorrect syntax so it is invalid. | ||
| 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. It's actually``char*. This is because the * in ++argv dereferences the char* argv, leading to char **. The incrementing actually does nothing. In the same way that int x = 1; ++x would still be an int!` | ||
| .9)invalid is invalid as main is a function and this should not work. | ||
| 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. Functions in C are actually just pointers to a spot in the program where some code exists. Just like you've been creating pointers to structs, strings, and arrays, you can point a pointer at a function too. The main use for this is to pass "callbacks" to other functions, or to simulate classes and objects. In this exercise we'll do some callbacks, and in the next one we'll make a simple object system. The format of a function pointer goes like this: 
 So the answer is actually  | ||
| .10) it will return a value that is is 6 | ||
| 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. Like I said in class, this is just a definition question, so the answer is 8 because pointers always allocate 8 bytes. | ||
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| #include<stdio.h> | ||
|  | ||
| int strcmp(char*,char*); | ||
| char* strct(char*,char*); | ||
|  | ||
|  | ||
|  | ||
| int main(){ | ||
|  | ||
| printf("\n"); | ||
| char *a = {"Hello"}; | ||
| char *b = {"World"}; | ||
| int aa=strcmp(a,b); | ||
| printf("%d",aa); | ||
| printf("\n"); | ||
| return 0; | ||
| } | ||
|  | ||
| char * strct(char *one, char *two){ | ||
| char a[(sizeof(one)+sizeof(two)-4)]; | ||
| int i=0; | ||
| while(*one!='\0'){ | ||
| a[i]=*one; | ||
| one++; | ||
| i++; | ||
| } | ||
| while(*two!='\0'){ | ||
| a[i]=*two; | ||
| two++; | ||
| i++; | ||
| } | ||
| a[i]='\0'; | ||
| one=a; | ||
| return one; | ||
| } | ||
|  | ||
|  | ||
| int strcmp(char* one,char* two){ | ||
|  | ||
| while(*one==*two){ | ||
| one++; | ||
| two++; | ||
| } | ||
| return ((int)(*one)-(int)(*two)); | ||
| } | ||
|  | ||
|  | ||
|  | ||
|  | ||
|  | ||
|  | ||
|  | ||
|  | ||
|  | ||
|  | ||
|  | ||
|  | ||
|  | ||
|  | 
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| //Clarke Littlejohn | ||
| //reverse.c | ||
| // i had no idea how to use the second pointer, it seems useless to me as i just used a tracker it see how far | ||
| //away the end was from the start | ||
|  | ||
| #include<stdio.h> | ||
|  | ||
|  | ||
| void reverse(char[]); | ||
|  | ||
| int main(){ | ||
|  | ||
| char str1[100]; | ||
|  | ||
| printf("Enter in a word."); | ||
| fgets(str1,sizeof(str1),stdin); | ||
| reverse(str1); | ||
|  | ||
| } | ||
|  | ||
|  | ||
| void reverse(char str1[]){ | ||
|  | ||
| int tracker = 0; | ||
| char* pStr=str1; | ||
| char* pStr2; | ||
| char start = *pStr; | ||
| while(*pStr!='\n'){pStr++;tracker++; } | ||
| *pStr='\0'; | ||
| printf("%s\n",str1); | ||
| for(;tracker>0;tracker--){ | ||
| pStr--; | ||
| printf("%c",*pStr); | ||
| } | ||
|  | ||
|  | ||
| } | 
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.
The expression ++*p has two operators of same precedence, so compiler looks for associativity. Associativity of operators is right to left. Therefore the expression is treated as ++(*p). The expression *p++ is treated as *(p++) as the precedence of postfix ++ is higher than *. The expression *++p has two operators of same precedence, so compiler looks for associativity. Associativity of operators is right to left. Therefore the expression is treated as *(++p).