logo codesdope

pointer to array section in C++

   tunuofmrec@gmail.com

#include<iostream>


using namespace std;

int main() {
        int ar[] = { 1,2,3,4,5,6,7,8,9,10 };
        int m=0;
        for (m : ar) {
                cout << m << endl;
        }

        return 0;
}
 

Not compiling:

pointer1.cpp: In function ‘int main()’:
pointer1.cpp:11: error: expected ‘;’ before ‘:’ token
pointer1.cpp:15: error: expected primary-expression before ‘return’
pointer1.cpp:15: error: expected ‘;’ before ‘return’
pointer1.cpp:15: error: expected primary-expression before ‘return’
pointer1.cpp:15: error: expected ‘)’ before ‘return’
 

 

 


Answers

  •    Aakhya Singh

    loops over the array arr and takes it value from its elements. You need to define it as shown below.

    for (int m : ar) 
            cout << m << endl;
    

     



  •    sneha gulati

    I agreed with Aakhya Singh. Thank you.



Download Our App.
BlogsDope App
Get it on Google Play
Write your answer
Close

Welcome.please sign up.

Close

Welcome.please login.