<aside> 💡
editor ~ Manohar Gella
</aside>
Topic Name | Sub-Topics |
---|---|
C++ Intermediate | Scope |
Loops | |
Arrays | |
Nested Loops | |
Pattern printing |
a scope is a region of a program, every pair of curly braces create a new scope, the variable inside the scope are can not be used in other SCOPE but variable which are not within the curly braces are can be used in any SCOPE
#includle <iostream>
int main(){
for(int i = 0; i<=10; i++){
i++;
}
// here 'i' variable can be only access by within for loop not
return 0;
}
The score resolution operator is used when the the global variable and the scope variable have same variable name but need to use int he scope the we use “::” symbol
#include <iostream>
int i = 20;
int main(){
int i = 2;
cout << i << endl; // this give the value if i with in the scope
cout << ::i << endl; // this give the value of i outside the scope
return 0;
}
/*
Example output:
2
20
*/
used to repeat task for multiple times
#include <bits/stdc++.h>
using namespace std;
int main(){
string name = "Manohar";
for(int i = 0; i<=10; i++){
cout << name << endl;
}
return 0;
}
// here the code prints name util in reaches 10;
predefined int
#include <iostream>
using namespace std;
int main(){
int i = 0;
for(; i<=10; i++){
cout << "Manoahr Gella";
}
}
#include <bits/stdc++.h>
using namespace std;
int main(){
for(int i = 0, j = 0; i<=5 && j<=12; i++, j++){
cout << "Randi" << endl;
}
return 0;
}