Pages

Tuesday, April 8, 2025

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

 #include<iostream>

using namespace std;

void printArr(int *ptr, int n) {
    for(int i=0; i<n; i++) {
        cout << (*ptr+i) << endl;
        }
}



int main(){
    int arr[] = {1, 2, 3, 4, 5};
    int n = sizeof(arr) / sizeof(int);
   
    printArr(arr, n);
    return 0;
}

OUTPUT-
1
2
3
4
5

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