Pages

Tuesday, April 8, 2025

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

 #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 << endl; // 4
    cout << *ptr1 << endl; // 1

    cout << ptr2-ptr1 << endl;

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

    return 0;
}

OUTPUT-
4 1 3

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...