Created
December 18, 2014 07:41
-
-
Save zneo/2d46b551c1ddcab9ae8d to your computer and use it in GitHub Desktop.
cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream.h> | |
| #include <string.h> | |
| #include <stdlib.h> | |
| void main() | |
| { | |
| for (int i =1;i<5; ++i) | |
| { | |
| static int a = i; | |
| cout << a <<endl; | |
| } | |
| } |
include
include <string.h>
include <stdlib.h>
using namespace std;
int main()
{
for (int i =1;i<5; ++i)
{
static int a=i;
cout << a <<endl;
}
return 0;
}
it always prints the no assigned to it during declaration ie 1;
so u have increment it like
include
include <string.h>
include <stdlib.h>
using namespace std;
int main()
{
for (int i =1;i<5; ++i)
{
static int a=i;
cout << a <<endl;
a++;
}
return 0;
}
output:1
2
3
4
for this output is
include
include <string.h>
include <stdlib.h>
using namespace std;
int main()
{
for (int i =1;i<5; ++i)
{
static int a;
cout << a <<endl;
a++;
}
return 0;
}
output : 0
1
2
3
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
include <iostream.h>
include <string.h>
include <stdlib.h>
void main()
{
for (int i =1;i<5; ++i)
{
static int a = i;
std::cout << a <<std::endl;
}
}
it always print 0 fore times
And
include <iostream.h>
include <string.h>
include <stdlib.h>
void main()
{
for (int i =1;i<5; ++i)
{
static int a = i;
std::cout << a <<std::endl;
a++;
}
}
it print:- 1 2 3 4 in all iteration