Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

C - Programming ( Output based - Loop )

Total questions: 10

Worksheet time: 10mins

Name
Class
Date
1.

Which of the following is the correct output for the program given below.

#include <stdio.h>

void main()

{

int arr[5],i=-1,z;

while(i<5)

arr[i]=++i;

for(i=0;i<5;i++)

printf (“ %d”,arr[i]);

}

a)

0 1 2 3 4

b)

0 -1 -2 -3 -4

c)

-1 0 1 2 3 4

d)

1 2 3 4 5

2.

What will be the output of following prog . ?

#include <stdio.h>

void main()

{

int arr[]= {0,1,2,3,4};

int i, *p;

for(p=arr, i=0;p+i<=arr+4;p++,i++)

printf(“%d”,*(p+i));

}

a)

0,2,4

b)

0,1,2

c)

0,2,3

d)

2,3,4

3.

which of the following statements is correct :

#include <stdio.h>

int main()

{

int i,x;

for(i=1;i<=(9%2 +i); i++)

{

x=(i*3 + i*2)/I;

printf("%d",x);

}

}

a)

The code prints output as 5 10

b)

The code prints output as 5 5 5 5

c)

The code prints 5 infinite numbers of times

d)

The code prints 20 infinite numbers of times

4.

What will be the output of following prog . ?

#include <stdio.h>

void main()

{

static int arr[] ={2,3,4,5,6};

int i;

for(i=5;i>0;)

printf(“%d”,arr[--i]);

}

a)

6 5 4 3 2

b)

2 3 4 5 6

c)

5 4 3 2 0

d)

no output

5.

The function test is coded as follows:

int test(int num)

{

int m,n=0;

while(num)

{

m=num%10;

if(m%2)

n=n+1;

num=num/10;

}

return(n);

}

What will be the values of x and y when the following statements are executed?

int x= test(135);

int y == test(246);

a)

0,0

b)

0,3

c)

3,0

d)

3,3

6.

Which of the following is the correct output for the program given below.

#include <stdio.h>

void main()

{

char *p="hai friends",*p1;

p1=p;

while(*p!='\0') ++*p++;

printf("%s %s",p,p1);

}

a)

hai friends

b)

ibj!gsjfoet

c)

ibj!gsjfoet hai friends

d)

Error

7.

Which of the following is the correct output for the program given below.

Void main()

{ int i=0;

for(;++i;) ;

printf("%d",i);

}

a)

0

b)

1,2,3,4,5,.....

c)

1

d)

No Output

8.

Which of the following is the correct output for the program given below.

#include <stdio.h>

Void main()

{ int i=0;

for(;i++;printf("%d",i)) ;

printf("%d",i);

}

a)

0

b)

1 1 2 2 3 3 4 4 5 5 ………

c)

1

d)

No Output : Error

9.

Which of the following is the correct output for the program given below.

#include <stdio.h>

void main()

{

unsigned int i;

for(i=1;i>-2;i--)

printf("Hi ");

}

a)

Hi Hi Hi

b)

no output

c)

Hi Hi Hi Hi…………

d)

None of these

10.

Which of the following is the correct output for the program given below.

#include <stdio.h>

void main()

{

unsigned int i=10;

while(i-->=0)

printf("%u ",i);

}

a)

9 8 7 6 5 4 3 2 1 0 65535 65534…..…..infinite times

b)

9 8 7 6 5 4 3 2 1 0 65535

c)

9 8 7 6 5 4 3 2 1 0 -1

d)

none of these