int x;
int z=0;
for( x=0; x<5; x++)
{
z++;
if( x <3 ) continue;
if( x>3 ) break;
z++;
}
printf(“%d\n”, z);
a Z=1
b. Z=6
c. Z=7
d. Z=9
e. Z=10
Showing posts with label loops. Show all posts
Showing posts with label loops. Show all posts
Tuesday, May 12, 2009
Saturday, November 29, 2008
Predict the counter value
x = 3, counter = 0;
while ((x-1))
{
++counter;
x--;
}
Choice a: 0
Choice b: 1
Choice c: 2
Choice d: 3
Choice e: 4
while ((x-1))
{
++counter;
x--;
}
Choice a: 0
Choice b: 1
Choice c: 2
Choice d: 3
Choice e: 4
Friday, November 28, 2008
Point out the error if any
main() {
int i=1;
while()
{ printf("%d",i++);
if(i>10) break; }
}
a. The condtion in the while loop is must
b. There should be atleast a semicolon in the while()
c. The while loop should be replaced by the for loop
d. No Error
int i=1;
while()
{ printf("%d",i++);
if(i>10) break; }
}
a. The condtion in the while loop is must
b. There should be atleast a semicolon in the while()
c. The while loop should be replaced by the for loop
d. No Error
Wednesday, October 29, 2008
What will happen when the program below is compiled and executed?
int i;
int increment( int *i )
{
return ++i;
}
int main()
{
for( i = 0; i < 10; increment(i) )
{}
printf("i=%d", i);
return 0;
}
Choice a: It will not compile
Choice b: It will print out i=9
Choice c: It will print out i=10
Choice d: It will print out i=11
Choice e: It will loop indefinitely
int increment( int *i )
{
return ++i;
}
int main()
{
for( i = 0; i < 10; increment(i) )
{}
printf("i=%d", i);
return 0;
}
Choice a: It will not compile
Choice b: It will print out i=9
Choice c: It will print out i=10
Choice d: It will print out i=11
Choice e: It will loop indefinitely
Subscribe to:
Posts (Atom)