Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help with this C++ Pointers Variables code. For part 2 I do not know why it shows the half of integers numbers located

I need help with this C++ Pointers Variables code. For part 2 I do not know why it shows the half of integers numbers located in the array. NOTE: part 2 should not use loop counter and rather use pointer arithmetic. It will be grateful if somebody can help me with the code, Thanks.

The steps are here:

https://www.dropbox.com/s/s6bvy79p3m9yyiz/Assignment%2010.docx?dl=0

And the code is here:

part2.cpp

#include using namespace std; const int SIZE = 20;

int main() { int numbers[SIZE] = { 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20 }; char ch[SIZE] = { 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T' }; int * iptr = numbers; char *cptr = ch; cout << "printing EVERY element of char array using cptr " << endl; for (int i = 0; i < SIZE; i++) { //every element cout << *cptr << " "; cptr++; } cout << endl; cout << "printing EVERY OTHER element of int array using iptr" << endl; for (int i = 0; i < SIZE; i += 2) { //every other element cout << *iptr << " " ; iptr += 2; //increment pointer by 2 , every other element } system("pause"); return 0; }

output

printing EVERY element of char array using cptr A B C D E F G H I J K L M N O P Q R S T printing EVERY OTHER element of int array using iptr 1 3 5 7 9 11 13 15 17 19

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Processing Fundamentals, Design, and Implementation

Authors: David M. Kroenke, David J. Auer

14th edition

133876705, 9781292107639, 1292107634, 978-0133876703

More Books

Students also viewed these Databases questions