C Programming - Control Instructions - Discussion

Discussion Forum : Control Instructions - Find Output of Program (Q.No. 19)
19.
What will be the output of the program?
#include<stdio.h>
int main()
{
    char j=1;
    while(j < 5)
    {
        printf("%d, ", j);
        j = j+1;
    }
    printf("\n");
    return 0;
}
1 2 3 ... 127
1 2 3 ... 255
1 2 3 ... 127 128 0 1 2 3 ... infinite times
1, 2, 3, 4
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
24 comments Page 1 of 3.

Dev said:   12 months ago
Here, it will be int i=1.

Shashank Mishra said:   2 years ago
How can be char j =1?
1 is an integer so j should be int datatype.

Jat said:   3 years ago
Anyone, explain the meaning of %d in this printf("%d, ", j).

Nellaiappan N said:   9 years ago
Thanks for your answer @Padhu.

Sonamuthu said:   1 decade ago
While loop execute 4 times so will print 1, 2, 3, 4.
(1)

Narendra.n.h said:   1 decade ago
This above statement will print value along with comma. For example:

int j=9;
printf ("%d, ", j) ;

Output:9,
(2)

Sanjoy said:   1 decade ago
printf ("%d, ", j) ;.

Why there is a comma after the symbol d?
(1)

Srk said:   1 decade ago
%i means it will print integral type values like octal,decimal and hexadecimal.

Sudheer said:   1 decade ago
What is meaning of %i in c language I mean it declares which data type can any one tell me?

Gunjan dhawas said:   1 decade ago
here j is char which is of 1 byte. In 1 byte we can have number from 0 to 255.(2^8=256)as 1 byte=8 bits.

Hence using char as data type we can store integer values up to 255.


Post your comments here:

Your comments will be displayed after verification.