Skip to content

atmilich/Assignment7

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Assignment7

Objectives

To gain an understanding of pointers.

Part 1

  1. In a program reverse.c, write a string reversal function using pointers that takes only a string as input, creates 2 pointers, performs a string reversal using those pointers, and prints out the reversed string. Your driver should take a string input by the user using fgets().

Part 2

In a text file assignment7.txt, answer the following questions:

  1. Explain the difference between ++*p, *p++ and *++p, if there is any.
  2. Is the left to right or right to left order guaranteed for operator precedence?
  3. What are the advantages of using pointers?
  4. Consider a C program’s main() function that starts as follows:
    int main(int argc, char **argv) {
      int a[10] = { 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 };
      int *p = a + 2;
      char *str = "hello";
  • For integer expressions (i.e., the expressions whose types are char, short, int, size_t, long, or long long--either signed or unsigned), write the actual number value.

  • For non-integer expressions, write the type name, in the format that you use to declare a variable of that type. Some example type names include but are not limited to:

      int *
      double
      double **
      int(*)(int)
  • Write "invalid" if a given expression is not a valid C expression.

  • Make sure sure to explain each of your answers.

4.1 "abc"
4.2 "xyz"[1] - ’y’
4.3 ’\0’ == 0
4.4 *a
4.5 &a[0]
4.6 *p
4.7 &p
4.8 *++argv
4.9 &main
4.10 sizeof(str)

Part 3:

Submit your final project proposal in the "Final Project" Repository.

Submission Guidelines

Please include your name and a description in a comment at the top of your code files. Please also include your name at the top of your assignment7.txt file.

All files must be submitted via GitHub by 10:00am 7/11.

About

Assignment 7

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C 100.0%