C Programming - Pointers - Discussion

Discussion Forum : Pointers - Point Out Correct Statements (Q.No. 3)
3.
Which of the statements is correct about the program?
#include<stdio.h>

int main()
{
    float a=3.14;
    char *j;
    j = (char*)&a;
    printf("%d\n", *j);
    return 0;
}
It prints ASCII value of the binary number present in the first byte of a float variable a.
It prints character equivalent of the binary number present in the first byte of a float variable a.
It will print 3
It will print a garbage value
Answer: Option
Explanation:
No answer description is available. Let's discuss.
Discussion:
50 comments Page 3 of 5.

Siri said:   9 years ago
but we are printing %d with %d how ASCII value will print?

Pranali said:   8 years ago
@Siri.

ASCII value is in the form of integer. And for printing decimal integer we have used %d format specifier. Got it?

Zdd said:   7 years ago
@Vishwas.

3.14D = 11.0010001111010111B.

the format of float:SEEEEEEE EMMMMMMM MMMMMMMM MMMMMMMM
S: it's 0, it's a postive
E: 10000000 (1+127), the index part is 1.E is positive, hence the base's decimal point move to the right by 1 digit, otherwise, move to the left.
M: (1.)10010001111010111here omitted a 1. in the left.

Then The decimal point is shifted to the right by 1 digit, i.e. 11.0010001111010111B i.e. 3.14D.

Hence it is stored as 01000000 0100100 11110101 11000011 (the width of float is 4 bytes).

Noel Nosse said:   7 years ago
This problem/code appears to me to have been written with errors.

The %d in the printf does not match the float or char. If you make both the value (which is float 3.14) AND the pointer a float AND change the %d to %f, you get the meaningful printing of the 3.14.

Can anyone help me to get it of?

Parmeshwar said:   6 years ago
It's a garbage value -61 ... And the float.
It's a cycle of signed range.... -127 to 127.

Mukta said:   4 years ago
@HImanshu Chauhan.

printf prints it in a format you want and scanf accepts whatever you enter.

Gourav said:   1 decade ago
C stores local variables on stack.

Global variables may be declared. These are not stack based. But stored in the data segment.

Vinod said:   1 decade ago
Can you explain how to came -61.

Durai pandian said:   1 decade ago
Please whats the meaning of the -61 as output.

Mukesh said:   1 decade ago
Where the global variable stored in c language?


Post your comments here:

Your comments will be displayed after verification.