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

3917. Count Indices With Opposite Parity (Brute Force) O(n2) + Optimized Solution O(n) + tips LEETCODE WEEKLY 500

  class Solution {     public int [] countOppositeParity ( int [] nums ) {          // approach 1 - checks every pair         int n = n...