Unsigned char c;
for ( c=0;c!=256;c++2)
printf("%d",c);

No. of times the loop is executed ?

Answers were Sorted based on User's Feedback



Unsigned char c; for ( c=0;c!=256;c++2) printf("%d",c); No. of times t..

Answer / subbu

instead of "c++2" if there is "c++" it will not give any
errors. output will be continuosly for infinite number of
times.

Is This Answer Correct ?    16 Yes 0 No

Unsigned char c; for ( c=0;c!=256;c++2) printf("%d",c); No. of times t..

Answer / shalabh

This will be an infinite loop as the value of unsigned char
cannot exceed 255....c++2 can be errornous..but the value
of unsigned char cannot go beyond 255

Is This Answer Correct ?    5 Yes 1 No

Unsigned char c; for ( c=0;c!=256;c++2) printf("%d",c); No. of times t..

Answer / manishsoni

It produce compile time error becoz the statement c++2 is
not allowed here.

if this statement is written as c+=2,then it will give us an
infinite loop between
0--->254----->0---->254...
because it check simply c!=256(mean c is not equal to
256,mean it simply it didnot print the value at 256,that
mean it did not print 256...after 254...and print 0)
------------------------------------------------------------
No. of times the loop is executed ?
------------------------------------------------------------
loop will execute 128 times becoz:
the loop is increased each time by 2 and loop is execute
254 time without zero so
254/2=127
127+1(zero)=128;
so the loop is execute 128 times....
BY:ManisH SonI(MoNu)

Is This Answer Correct ?    4 Yes 1 No

Unsigned char c; for ( c=0;c!=256;c++2) printf("%d",c); No. of times t..

Answer / sundeep

First of all the code returns compile time error....bcoz
of "c++2",and c!=256 becoz unsigned char takes just 255
bytes..........and exceeding that results in compile time
error........

Is This Answer Correct ?    6 Yes 4 No

Unsigned char c; for ( c=0;c!=256;c++2) printf("%d",c); No. of times t..

Answer / manish soni

IT SHOW ACTUAL O/P.
main()
{
int c;
int i=1;
for ( c=0;c!=256;c+=2)
{
printf("%d=%d\n",i,c);
i++;
}
getch();
}

MANISH SONI
[GYAN CORPORATION,CHANDIGARH]

Is This Answer Correct ?    1 Yes 0 No

Unsigned char c; for ( c=0;c!=256;c++2) printf("%d",c); No. of times t..

Answer / prabu

infinite loop executed

Is This Answer Correct ?    0 Yes 0 No

Unsigned char c; for ( c=0;c!=256;c++2) printf("%d",c); No. of times t..

Answer / manishsoni

The program is as:
------------------------------------------------------------
#include<stdio.h>
#include<conio.h>
int main()
{
unsigned char c;
for(c=0;c!=256;c++2)
{
printf("%d",c);
printf("\n");
}

getch();
}

Is This Answer Correct ?    0 Yes 1 No

Unsigned char c; for ( c=0;c!=256;c++2) printf("%d",c); No. of times t..

Answer / sanjeev

this loop is executed at 254 times.

Is This Answer Correct ?    2 Yes 7 No

Post New Answer

More C Interview Questions

An instruction which is analysed and acted upon by the processor prior to the compiler going its work a) directive b) constructive c) constant d) absolute mode

0 Answers  


What does c mean before a date?

0 Answers  


Explain what is the difference between declaring a variable and defining a variable?

1 Answers  


Explain why can’t constant values be used to define an array’s initial size?

0 Answers  


34.what are bitwise shift operators? 35.what are bit fields? What is the use of bit fields in a structure declaration? 36.what is the size of an integer variable? 37.what are the files which are automatically opened when a c file is executed? 38.what is the little endian and big endian? 39.what is the use of fflush() function? 40.what is the difference between exit() and _exit() functions? 41.where does malloc() function get the memory? 42.what is the difference between malloc() and calloc() function? 43.what is the difference between postfix and prefix unary increment operators?

3 Answers  






int array[]={1,2,3,4,5,6,7,8}; #define SIZE (sizeof(array)/sizeof(int)) main() { if(-1<=SIZE) printf("1"); else printf("2"); }

2 Answers   Vector,


Why functions are used in c?

0 Answers  


What are file streams?

0 Answers  


What is null pointer in c?

0 Answers  


What is the difference between realloc() and free()

1 Answers  


Explain what does it mean when a pointer is used in an if statement?

0 Answers  


write a program to display the numbers in the following 4 4 3 3 2 2 1 1 0 1 1 2 2 3 3 4 4

1 Answers  


Categories