What does ":" mean?? Or what does it do | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

What does ":" mean?? Or what does it do

Arrays in loop

18th Mar 2019, 8:06 PM
Williams Nengi
Williams Nengi - avatar
4 Answers
+ 6
Its usally used inside an enhanced for loop it is usually read as "in". Edit: Just found this which might help i actually learned somthing too here thanks ☺.. https://stackoverflow.com/questions/2399590/what-does-the-colon-operator-do
18th Mar 2019, 9:55 PM
D_Stark
D_Stark - avatar
+ 2
Where did you see this? Can you give an example? Edit: Do you mean the last code example in this lesson? https://www.sololearn.com/learn/CPlusPlus/1627/?ref=app
18th Mar 2019, 8:50 PM
Denise Roßberg
Denise Roßberg - avatar
+ 2
Williams Nengi " " <-- String A String can be everything. "Hello", "123", "+" If you look in the code: The Author of this code want to print x and myArr[x]. The intention of printing : is to look it better or to separate x from myArr[x]. Play around with the code and see what happens when you remove ":" or when you insert "-". (Tap "try it yourself")
19th Mar 2019, 2:13 PM
Denise Roßberg
Denise Roßberg - avatar
0
Int myArr[5]; For(int x=0;x<5;x++) { MyArr[x] =42; Cout<<x<<":"<<myArr[x] <<endl;
19th Mar 2019, 7:42 AM
Williams Nengi
Williams Nengi - avatar