Pages

Tuesday, April 8, 2025

Pointer Arithmetic in C++ - 4 (CAN BE ASKED IN INTERVIEW)

 #include<iostream>

using namespace std;


int main(){
    // int a = 5;

    int arr[20] = {1, 2, 3, 4, 5, 6};
    int *ptr1 = arr; //
    int *ptr2 = ptr1 + 3; //4

    cout << (ptr2 == arr) << endl;
// yes : true : 1 (ptr1 == arr) OUTPUT- 1 (yes points
to same memory location)

    // cout << ptr2 - ptr1 << endl;

    return 0;
}




OUTPUT-
0

No comments:

Post a Comment

Encode and Decode Strings - NeetCode.IO Solution by me + gemini pro 3.0 explained

  class Solution {         // encode: List of Strings -> String     public String encode ( List < String > strs) {         Stri...