Question

In: Computer Science

for C++ pointers: a. Given int arr [10], *ap = &arr[2]; what is the result of...

for C++ pointers:

a. Given int arr [10], *ap = &arr[2]; what is the result of (ap - arr)?

b. Given int val = 10, *x = &val, *y; y = x; *y=100; what is the output of cout << *x << *y;?

c. Given int arr [10], *ap = arr; what element does ap point to after ap +=2; ?

Solutions

Expert Solution

a)

b)

c)


Related Solutions

C Write a function int sort(int** arr, int n) that takes as input an array of...
C Write a function int sort(int** arr, int n) that takes as input an array of int pointers, multiplies the ints the pointers point to by -1, and then sorts the array such that the values pointed to by the pointers are in decreasing order. For example, if the array is size 10 the pointer at index 0 will point to the largest value after multiplying by -1 and the pointer at index 9 will point to the smallest value...
Given the root C++ code: void sort() {    const int N = 10;    int...
Given the root C++ code: void sort() {    const int N = 10;    int x[N];    for(int i = 0; i < N; i++)    {        x[i] = 1 + gRandom-> Rndm() * 10;        cout<<x[i]<<" "; }    cout<<endl;    int t;       for(int i = 0; i < N; i++)    {    for(int j = i+1; j < N; j++)    {        if(x[j] < x[i])        {   ...
C Write a function that takes as input an array of int pointers, multiplies the ints...
C Write a function that takes as input an array of int pointers, multiplies the ints the pointers point to by -1, and then sorts the array such that the values pointed to by the pointers are in decreasing order. For example, if the array is size 10 the pointer at index 0 will point to the largest value after multiplying by -1 and the pointer at index 9 will point to the smallest value after multiplying by -1. If...
Evaluate the following expressions: (int)(18.357 * 100)/10 result: _____________ (int)18.357 * 100/10.0 result: _____________ int x...
Evaluate the following expressions: (int)(18.357 * 100)/10 result: _____________ (int)18.357 * 100/10.0 result: _____________ int x = 5; int y = 8; int z = ++x - y--; x=_____ y=_____ z=_____ int a = 20; int b = 10; a -= b - 15; a=_____ b=_____   CSE 118 Fundamentals of programming Java 14.0
C++ 1) Given Arr[10] = {7, 9, 13, 15, 16, 10, 12, 5, 20, 27} Write...
C++ 1) Given Arr[10] = {7, 9, 13, 15, 16, 10, 12, 5, 20, 27} Write a program to count number of EVEN and ODD items. Do a screen output of your result. 2) Given Arr[10] = {7, 9, 13, 15, 16, 10, 12, 5, 20, 27} Write a program to construct array ODD[] and EVEN[] from Arr[10] as you realize ODD[] consists of odd number and EVEN[] consists of even number.
C++ Given 2 int arrays that are related, sort them correspondingly. EXAMPLE: int arr1[] = {84,...
C++ Given 2 int arrays that are related, sort them correspondingly. EXAMPLE: int arr1[] = {84, 4, 30, 66, 15}; int arr2[] = {7, 5, 2, 9, 10}; SORTED ANSWER: 4 - 5 15 - 10 30 - 2 66 - 9 84 - 7 IN C++
This is C++ programming Given an int variable k, an int array incompletes that has been...
This is C++ programming Given an int variable k, an int array incompletes that has been declared and initialized, an int variable nIncompletes that contains the number of elements in the array, an int variable studentID that has been initialized, and an int variable numberOfIncompletes, Write code that counts the number of times the value of studentID appears in incompletes and assigns this value to numberOfIncompletes. You may use only k, incompletes, nIncompletes, studentID, and numberOfIncompletes. I tried this code...
#include <stdio.h> int main () { int value= 10; int value2= 5; value = value %2;...
#include <stdio.h> int main () { int value= 10; int value2= 5; value = value %2; printf("he FInal =value=%d\n", value); value +=3; printf("he FInal =value=%d\n", value); value ++; printf("he FInal =value=%d\n", value); value= ++value2; printf("he FInal =value=%d\n", value); value= value2--; printf("he FInal =value=%d\n", value); } what is output explain each print statement? exlain why?
c++ Define polymorphism. What is the benefit of using pointers with polymorphic functions?
c++ Define polymorphism. What is the benefit of using pointers with polymorphic functions?
5. Given the following declarations and assignments, what do these expressions evaluate to? int a1[10] =...
5. Given the following declarations and assignments, what do these expressions evaluate to? int a1[10] = {9, 8, 7, 6, 5, 4, 3, 2, 1, 0}; int *p1, *p2; p1 = a1+3; p2 = &a1[2]; (a) *(a1+4) (b) a1[3] (c) *p1 (d) *(p1+5) (e) p1[-2] (f) *(a1+2) (g) a1[6] (h) *p2 (i) *(p2+3) (j) p2[-1]
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT