Pages

Tuesday, April 22, 2025

Char Array (for each loop) in C++

#include <iostream>

#include <cstring>

using namespace std;



int main()

{

    string str = "apna college";

    

    

    // for(int i=0; i<str.length(); i++) {

    //     cout << str[i] << "-";

        

    // } cout << "\n";

        

        for(char ch : str) {

            cout << ch << ",";

        } cout << endl;

    

    // for(char ch : str) {

    //     cout << ch << ",";

    // }

    // cout << endl;


    return 0;

}

No comments:

Post a Comment

remove duplicates from sorted array - two pointer approach (leetcode)

  class Solution {     public int removeDuplicates ( int [] nums ) {         // base case: return if array have no el.         if ( nums...