Concept explainers
a)
The content of array is been initialized with given values and “*p” is assigned to the beginning of the array, now after executing each instructions individually results are obtained given below.
Explanation of Solution
Explanantion:
In the above program , an integer array is been declared first. A pointer “p” points to array. The pointer “p” is been incremented to obtain second element of integer array. Finally,program displays contents of array and value of “p”
Therefore, the content of “intArray” will be
Explanation of Solution
b)
(*p)++;
The integer pointer “p” points to first elemenst of the array. So, “*(p)++” denotes that first element of array is been incremented first and then it is assigned to “*p”. Hence, first element of array increments as a result of this instruction.
This program shows execution of the construct and displays the result of the array and value of “p”.
Program:
//Select header files
#include <stdio.h>
#include<iostream>
using namespace std;
// Main function
int main(void)
{
// Integer array with declaration
int arr[] = {1,2,3};
Here, “p” denotes pointer to integer array...
Explanation of Solution
Explanantion:
In the above program an integer array is declared first. A pointer “p” points to array. The content pointed to by “p” is been incremented . Finally program displays contents of array and value of “p”.
Therefore, the content of “intArray” will be
Explanation of Solution
c)
*p++; (*p)++;
The integer pointer “p” points to first element of array. So, *p++ denotes second element of array. Hence, second element of array increments and the incremented value is stored in “p”.
This program shows the execution of the construct and displays result of array and value of “p”.
Program:
//Select header files
#include <stdio.h>
#include<iostream>
using namespace std;
// Main function
int main(void)
{
// Integer array with declaration
int arr[] = {1,2,3};
...Explanation of Solution
Explanantion:
In the above program an integer array is declared first. A pointer “p” points to array. The pointer is incremented, so that it now points to second element of array . Now, the contents pointed to by “p” is been incremented. Finally the program displays contents of array and value of “p”
Therefore, the content of “intArray” will be
Want to see the full answer?
Check out a sample textbook solutionChapter 1 Solutions
EBK DATA STRUCTURES AND ALGORITHMS IN C
- An array is a container object that holds a fixed number of values of a single type. To create an array in C, we can do int arr[n];. Here, arr, is a variable array which holds up to integers. The above array is a static array that has memory allocated at compile time. A dynamic array can be created in C, using the malloc function and the memory is allocated on the heap at runtime. To create an integer array, of size , int *arr = (int*)malloc(n * sizeof(int)), where points to the base address of the array. When you have finished with the array, use free(arr) to deallocate the memory. In this challenge, create an array of size dynamically, and read the values from stdin. Iterate the array calculating the sum of all elements. Print the sum and free the memory where the array is stored. While it is true that you can sum the elements as they are read, without first storing them to an array, but you will not get the experience working with an array. Efficiency will be required later.…arrow_forwardWrite a program that simulates a toy paging system that uses the WSClock algorithm. The system is a toy in that we will assume there are no write references (not very realistic), and process termination and creation are ignored (eternal life). The inputs will be: The reclamation age threshhold The clock interrupt interval expressed as number of memory references A file containing the sequence of page references Describe the basic data structures and algorithms in your implementation. Show that your simulation behaves as expected for a simple (but nontrivial) input example. Plot the number of page faults and working set size per 1000 memory references. Explain what is needed to extend the program to handle a page reference stream that also includes writes.arrow_forwardThis is a java data structures question - Given a circular bent array-based queue capable of holding 100 objects. Suppose the queue is initially empty, and then objects are put into the queue at the rate of 10 per minute while meantime they are processed and removed from the queue at the rate of 5 per minute. After 120 elements have been added to the queue, which of the following is true? CIRCLE JUST ONE LETTER FOR THE ANSWER. -> You can’t add 120 elements to an array holding 100 entries. -> There will be 60 elements in the queue, 20 of them at the front of the array where the queue started, and 40 at the other end. -> There will be 60 elements in the queue, 30 of them at the front of the array where the queue started, and 30 at the other end. -> There will be 60 elements in the queue, 40 of them at the front of the array where the queue started, and 20 at the other end.arrow_forward
- How can one simply copy a collection of shared pointers into another array using the C++ programming language? Create a list of potential answers to the problems you've been presented with in this scenario. Is it true that when shared pointers are copied, the objects they control are likewise copied along with them? Explainarrow_forwardWrite a Java program using OOP concept that perform the union and symmetric difference between two sets. Use class, object and method in code. A = { a, b, c, e, f }B = { d, e, f, g }arrow_forwardPlease Help In JAVA Here is the skeleton of a code for insertion sorting in a functional language. You have to add right lines of codes for the language you choose (C, C++, C#, JAVA etc,). The following sample is for C++ (define (insert L M) (if (null? L) M (if (null? M) L (if (< (car L) (car M)) (cons (car L) (insert (cdr L) M)) (cons (car M) (insert (cdr M) L)))))) ;; Exp. (insertionsort '(4 2 10 3 -1 5)) ==> (-1 2 3 4 5 10)(define (insertionsort L) (if (null? L) '() (insert (list (car L)) (insertionsort (cdr L))))) (define (random-list n) (unless (exact-nonnegative-integer? n) (raise-argument-error 'make-list "exact-nonnegative-integer?" 0 n)) (let loop ([n n] [r '()]) (if (zero? n) r (loop (sub1 n) (cons (random 2147483647) r))))) Sample function call:(insertionsort (random-list 10000)) Hint: most languages have some function to determine the runtime of functionsarrow_forward
- When it comes to data types, what are the pros and downsides of using user-defined ordinal kinds? An associative array has many benefits and downsides, which we will discuss in detail below.arrow_forwardConsider the following segment of code:procedure Mvar x: integer;procedure A (c: integer)var a, b: integer;procedure Bvar b, c, d: integer;begin {B}….a := c – d;….end B;begin {A}….x := b + c;….B()….end A;begin {M}….A(3)….end M;Assuming the definition of M is at static nesting level 0. Draw the runtime stack that will be ineffect at the execution of “a := c – d;”. Show the static and dynamic links, and the currentpositions of the EP and SP pointers.What is the static distance to x’s environment of definition and the offset within the environmentwhen “a := c – d;” is executed?arrow_forwardWrite a C++ program define a vector object and initialize it with 3 values and then define an iterator that points to elements of this object, then ask the user to enter 3 more values and then add them to the previous vector and then print all elements in the vector.arrow_forward
- Write a program that benchmarks QuickSort and InsertionSort. You should use at least 5 different data sets and record the performance of each algorithm on the same sets under the same conditions. Write a short report that compares the two algorithms based your results. It is important to include a discussion of the initial states of the data sets in your report. language Java public class week3 {public static void main(String args[]){ //========================================================== //Question 1 testing //================== // Comment on benchmarking for Q1 results // // //========================================================== } static void quickSort(int f[], int p, int q){ if(q-p <= 1) ; //skip else{ int x; int i, j, k; // let x = middle element in f[p..q-1] x = f[(p+q)/2]; //x = f[p]; i = p; j = p; k = q; while(j != k){ if(f[j] == x) j = j + 1; else if(f[j] < x){ //swap f[j] with f[i] int temp; temp = f[j]; f[j] = f[i]; f[i] = temp; j = j + 1; i = i + 1; } else{…arrow_forwardWrite a C program that receives from the user five integers that should be stored in an array for five elements in the order they were typed. Your program must then go through the vector from the end to the beginning, printing the elements of the vector, that is, it must print in the reverse order from which they were typed. Skip a line for each printed element.arrow_forwardUsing the following UML, define the interface using Java programming language. <> DynamicList + capacity : int //initialized to 10 + add(int index, Object o): boolean + remove(int index): booleanarrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education