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 2 of 3.

Meera said:   2 decades ago
j is a declared as a char data type.Then how the while loop executes?and how we are assigning that int value to char type?

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)

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?

Sameer said:   1 decade ago
Thanks narendra.

Using which format strings in printf statement we convert char to int ?

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

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

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

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

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

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

Vivek kumar said:   1 decade ago
Could not understand.

Please help me.


Post your comments here:

Your comments will be displayed after verification.