C Programming :: Loop Control

NA
SHSTTON
4
Solv. Corr.
7
Solv. In. Corr.
11
Attempted
0 M:0 S
Avg. Time

1 / 60

What is the final value of i and final value of LOOPS ?
#include<stdio.h>
int main()
{
int i,j,k,l,lc=0;

printf("Enter the number  string:<1234 567>\n");
scanf("%2d%d%1d",&i,&j,&k);
for(;k;k--,i++) 
for(l=0;printf("%d %d\n",i,l);)
printf("LOOPS= %d\n", lc-1);
}

AI = 16 and LOOPS=169

BI = 0 and LOOPS=16

CCompilation Error

DNo output

 View Answer |  Discuss in Forum |  Workspace | Asked In Societe Generale |

Answer: Option A

Explanation:

How?

Workspace

NA
SHSTTON
3
Solv. Corr.
9
Solv. In. Corr.
12
Attempted
0 M:0 S
Avg. Time

2 / 60

What is the output of the following C Program?
#include<stdio.h>
int main()
{
int i;
for (i=9;i<13; i++)
printf("%d %0x ",i,i);
return 0;
}

A9 9 10 10 11 11 12 12

B9 10 11 12

C9 9 10 b 11 b 12 c

DCompilation Error

E9 9 10 a 11 b 12 c

Answer: Option E

Explanation:

Here is no explanation for this answer

Workspace

NA
SHSTTON
1
Solv. Corr.
13
Solv. In. Corr.
14
Attempted
0 M:0 S
Avg. Time

3 / 60

What is the output of the following C Program?
#include<stdio.h>
int main(){
    for(printf("1");!printf("0");printf("2"))
         printf("Aditya");
    return 0;
}

A10Aditya2

B10Aditya

C10Aditya210Aditya2

D10

ECompilation error

Answer: Option D

Explanation:

Here is no explanation for this answer

Workspace

NA
SHSTTON
2
Solv. Corr.
5
Solv. In. Corr.
7
Attempted
0 M:0 S
Avg. Time

4 / 60

What is the output of the following C Program?
#include<stdio.h> void main()
{
int c[ ]={2.8,3.4,4,6.7,5};
int j,*p=c,*q=c; 
for(j=0;j<5;j++) {
printf(" %d ",*c);
++q;       
}
for(j=0;j<5;j++){
printf(" %d ",*p);
++p;       
}
}

A2 3 4 6 5 2 3 4 6 5

B2 2 2 2 2 2 3 4 6 5

C2.8 3.4 4 6.7 5 2.8 3.4 4 6.7 5

DNone of these

ECompiler Error

 View Answer |  Discuss in Forum |  Workspace | Asked In Societe Generale |

Answer: Option B

Explanation:

Here pointer c is assigned to both p and q.
In first loop, only q is incremented and not c , the value 2 will be printed 5 times.
In second loop p itself is incremented. So the values 2 3 4 6 5 will be printed

Workspace

NA
SHSTTON
4
Solv. Corr.
4
Solv. In. Corr.
8
Attempted
0 M:0 S
Avg. Time

5 / 60

What is the output of the following C Program?
#include<stdio.h>
int main()
{
int i=0;
for(;i++;printf("%d",i)) ;
printf("%d",i);
return 0;
}

A0

B1

C2

DNone of these

Answer: Option B

Explanation:

before entering into the for loop the checking condition is "evaluated". Here it evaluates to 0 (false) and comes out of the loop, and i is incremented (note the semicolon after the for loop).

Workspace

NA
SHSTTON
1
Solv. Corr.
6
Solv. In. Corr.
7
Attempted
0 M:0 S
Avg. Time

6 / 60

What is the output of the following C Program?
#include<stdio.h>
int main()
{ 
unsigned int i; 
for(i=1;i>-2;i--)
printf("c aptitude");
}

Ac aptitude

Bc aptitude three time

Cno output No Error

DCompilation Error

ENone of these

 View Answer |  Discuss in Forum |  Workspace | Asked In Societe Generale |

Answer: Option C

Explanation:

Here "I" is an unsigned integer. It is compared with a signed value. Since the both types doesn't match, signed is promoted to unsigned value.
The unsigned equivalent of -2 is a huge value so condition becomes false and control comes out of the loop.

Workspace

NA
SHSTTON
2
Solv. Corr.
5
Solv. In. Corr.
7
Attempted
0 M:0 S
Avg. Time

7 / 60

What is the output of the following C Program?
#include<stdio.h>
void  main()
{
while(1){
if(printf("%d",printf("%d")))
break; 
else
 continue;
}
}

AGarbage values

BCompilation Error

Cno output No Error

Dstack Overflow

Answer: Option A

Explanation:

The inner printf executes first to print some garbage value. The printf returns no of characters printed and this value also cannot be predicted. Still the outer printf prints something and so returns a non-zero value. So it encounters the break statement and comes out of the while statement.

Workspace

NA
SHSTTON
3
Solv. Corr.
4
Solv. In. Corr.
7
Attempted
0 M:0 S
Avg. Time

8 / 60

What is the output of the following C Program?
#include<stdio.h>
void  main()
{
signed char i=0;
for(;i>=0;i++) ; 
printf("%d\n",i);
}

A256

B128

C-256

D-128

ECompilation Error

Answer: Option D

Explanation:

Notice the semicolon at the end of the for loop. Tee initial value of the i is set to 0.
The inner loop executes to increment the value from
0 to 127 and then it rotates to the negative value of -128.
The condition in the for loop fails and so comes out of the for loop. It prints the current value of i that is -128.

Workspace

NA
SHSTTON
4
Solv. Corr.
4
Solv. In. Corr.
8
Attempted
0 M:0 S
Avg. Time

9 / 60

What will be output of the following "c" code?
#include<stdio.h>
int main() { 
int i;
for(i=0;i<5;i++){
int i=10;
printf(" %d",i);
i++;
}
return 0;
}

A10 11 12 13 14

B10 10 10 10 10

C0 1 2 3 4

DInfinite loop

Answer: Option B

Explanation:

Here is no explanation for this answer

Workspace

NA
SHSTTON
5
Solv. Corr.
3
Solv. In. Corr.
8
Attempted
0 M:0 S
Avg. Time

10 / 60

Find out the error in the 'while' loop, if any ?
#include<stdio.hvoid main()
{
int i= 1;
while ()
{
printf("%d", i++);
if (i > 10)
break;
}
}

AThe condition in the while loop is a must

BThere should be at least a semicolon in the while ()

CThe while loop should be replaced by for loop

DNo error

 View Answer |  Discuss in Forum |  Workspace | Asked In Societe Generale |

Answer: Option A

Explanation:

Here is no explanation for this answer

Workspace