Question

In: Computer Science

Problem5: (5 pts) using c programming Given an array of integers named “simple” of length 8...

Problem5: (5 pts)

using c programming

Given an array of integers named “simple” of length 8 and filled as follows:

5

20

13

8

0

16

55

2

int x = 5;

int *p = &simple[3] ;

Write the values of x after each of the following executes (write unknown if cannot be determined): (hint: pointer moves to new location after each line)

x = *(p++);                                                   x = ___8_______________ p->simple[4]           

x = *( p + 1) ;                                               x = _____16______________ p- simple[4]   

x = simple[5] - *(p--);                                   x = ____16___________    p->simple[3]

x = *(--p);                                                    x = _____13__________ p->simple[2]      

x = simple[0] / simple[7];                            x = ____2________

I am not understanding how he is coming up with these answers all the way. I think the *(p++) throws me off. just looking for explanations thank you

Solutions

Expert Solution

code:

#include<stdio.h>
int main(){
   int simple[]={5,20,13,8,0,16,55,2}; //array initialization
   int x=5;           //initializing x
   int *p=&simple[3];       //assigning address
   x=*(p++);
   printf("%d\n",x);
   x=*(p+1);
   printf("%d\n",x);
   x=simple[5]-*(p--);
   printf("%d\n",x);
   x=*(--p);
   printf("%d\n",x);
   x=simple[0]/simple[7];
   printf("%d\n",x);
  
  
}

explanation:


Related Solutions

Use C Programming - Given an array of integers and a number K, find the smallest...
Use C Programming - Given an array of integers and a number K, find the smallest element in array greater than or equal to K. If such element exists in the array, display it otherwise display "-1". Example: Input:     8     1 3 4 7 8 9 9 10     5     where: First line represents the number of elements in the array. Second line represents the elements in the array. Third line represents the value of K. Output:     7 Explanation:...
(Programming: Counting threshold inversions) You’ll be given an array (of integers) and a threshold value as...
(Programming: Counting threshold inversions) You’ll be given an array (of integers) and a threshold value as input, write a program to return the number of threshold inversions in the array. An inversion between indices i < j is a threshold inversion if ai > t ∗ aj , where t is the threshold value given as input.
Complete the given C++ program (prob1.cpp) to read an array of integers, print the array, and...
Complete the given C++ program (prob1.cpp) to read an array of integers, print the array, and then find the index of the largest element in the array. You are to write two functions, printArray() and getIndexLargest(), which are called from the main function. printArray() outputs integers to std::cout with a space in between numbers and a newline at the end. getIndexLargest () returns the index of the largest element in the array. Recall that indexes start at 0. If there...
Q2 - 15 pts) Given a minimum unimodal array of integers, run the binary search algorithm...
Q2 - 15 pts) Given a minimum unimodal array of integers, run the binary search algorithm to find the minimum element. You need to show the initial and the iteration-level values of the left index, right index and middle index as well as your decisions to reduce the search space in each iteration. 0 1 2 3 4 5 6 7 8 9 33 32 27 26 24 22 21 8 7 3 IN C++ PLEASE
Q2 - 15 pts) Given a minimum unimodal array of integers, run the binary search algorithm...
Q2 - 15 pts) Given a minimum unimodal array of integers, run the binary search algorithm to find the minimum element. You need to show the initial and the iteration-level values of the left index, right index and middle index as well as your decisions to reduce the search space in each iteration. 0 1 2 3 4 5 6 7 8 9 33 32 27 26 24 22 21 8 7 3
Write a C++ program to find the number of pairs of integers in a given array...
Write a C++ program to find the number of pairs of integers in a given array of integers whose sum is equal to a specified number.
The purpose of this C++ programming assignment is to practice using an array. This problem is...
The purpose of this C++ programming assignment is to practice using an array. This problem is selected from the online contest problem archive, which is used mostly by college students worldwide to challenge their programming ability and to prepare themselves for attending programming contests such as the prestige ACM International Collegiate Programming Contest. For your convenience, I copied the description of the problem below with my note on the I/O and a sample executable. Background The world-known gangster Vito Deadstone...
C Programming Only Write a program that declares a one-dimensional array of integers with 24 elements....
C Programming Only Write a program that declares a one-dimensional array of integers with 24 elements. Fill the array with random integers (use a loop). Neatly output each element in the one-dimensional array. Next convert your one-dimensional array of 24 elements into a two-dimensional array of 6 x 4 elements. Neatly output each element of the two-dimensional array. The values will be identical to the one-dimensional array – you’re just converting from one dimension to two.
Given an array of integers, delete each element from the array which is a multiple of 5, and display the rest of the array.
Given an array of integers, delete each element from the array which is a multiple of 5, and display the rest of the array.Input:    6    2 3 4 11 22 320    where:First line represents the number of elements in the array.Second line represents the elements in the array.Output:    2 3 4 11 22Explanation: Element of the array 320 is the only one in the array which is a multiple of 5, so it is removed from the array.Assumptions:Array can be of size...
Ex 1. Show the contents of the array of integers 5 7 4 9 8 5...
Ex 1. Show the contents of the array of integers 5 7 4 9 8 5 6 3 each time a selection sort changes it while sorting the array into ascending order. Initial array:   5 7 4 9 8 5 6 3 ANSWER (Hint there are 8 lines, Show Array after each selection and swap):
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT