subtract from array using pointers c 2b 2b

Solutions on MaxInterview for subtract from array using pointers c 2b 2b by the best coders in the world

showing results for - "subtract from array using pointers c 2b 2b"
Silvia
26 Sep 2018
1#include<iostream>
2
3int main()
4{								
5  								    // [0], [1], [2], [3], [4]
6  char array_my_name [] {"amir"};  //   a,   m    i     r   null
7  
8  char *char_ptr1{nullptr};
9  char *char_ptr2{nullptr};
10  
11  char_ptr1 = &array_my_name[1];
12  char_ptr2 = &array_my_name[3];
13  									//amir
14  std::cout<<"in the string, "<< array_my_name 
15    					 //r 						2
16  <<"the charachter "<<*char_ptr2<<" is "<<(char_ptr2-char_ptr1)
17    							//m
18  <<"charchters away from "<<*char_ptr1<<std::endl;
19  
20  return 0;
21}