retagged by
383 views
1 votes
1 votes

what is the output???? and

how it internally converted to int when we are printing with %d format specifier??

when i run in my ide i got 50 as output and i donn’t know how it came?

can anyone explain how 50 came

#include <stdio.h>

int main()

{

    char a = '12';

 

    printf("%d", a);

 

    return 0;

}

retagged by

1 Answer

0 votes
0 votes
it prints the ascii value of last digit.

char a = '12';

In location a first ascii value of 1 will be stored and then it will be over written by ascii value of 2.

Now at location a  ascii value of 2 is present.

If we try to print it :  %d will return 50 which is ascii value of 2

                               %c will print 2

Related questions

0 votes
0 votes
2 answers
2
Debargha Mitra Roy asked Apr 10
99 views
What is the output of the below code?#include <stdio.h void main() { static int var = 5; printf("%d ", var ); if (var) main(); }a. 1 2 3 4 5b. 1c. 5 4 3 2 1d. Error
3 votes
3 votes
3 answers
3
Laxman Ghanchi asked May 19, 2023
1,157 views
#include<stdio.h void print(int n) { printf("Hello "); if(n++ == 0) return ; print(n); n++; } int main() { void print(); print(-4); }How many times printf execute?? And H...
0 votes
0 votes
1 answer
4
Laxman Ghanchi asked May 19, 2023
684 views
#include<stdio.h>void print(int n){ printf("Hello "); if(n++ == 0) return ; print(n); n++;}int main(){ void print(); print(-4);}