Examveda
Examveda

What will be the output of the following program code?
#include<stdio.h>
void main()
{
      int i = 10;
      void *p = &i;
      printf("%f", *(float *)p);
}

A. Error

B. 10

C. 0.000000

D. None of these.

Answer: Option C


This Question Belongs to C Program >> Pointer

Join The Discussion

Comments ( 11 )

  1. Dayan Bhoi
    Dayan Bhoi :
    2 years ago

    Sabb ka galat hai bc

  2. Abdulrhman Alyafai
    Abdulrhman Alyafai :
    3 years ago

    int id = 0;

    try{

    if (id == 0)

    throw new RuntimeException(“id is zero ”);

    } catch(RuntimeException e){

    System.out.print(e.getMessage());

    }

    finally{

    System.out.println("Close Program");

    }

  3. Abhay Chhetri
    Abhay Chhetri :
    3 years ago

    since the value that we are de referencing is integer type thus type casting in floating type will give the output 0.000. but if we will type cast in integer type then the output will be 10.

  4. Srav Shivkumar
    Srav Shivkumar :
    6 years ago

    when i execute this pgm i get an error stating main should return int.how is this showing 0.000? some pls explain

  5. PRADEEPCHIN2
    PRADEEPCHIN2 :
    6 years ago

    can anyone please explain this program.

  6. Mayur Patil
    Mayur Patil :
    6 years ago

    i cannot understand this typecast
    and output=0.000000

  7. SAKSHI MISHRA
    SAKSHI MISHRA :
    6 years ago

    We can de-reference a void pointer by typecasting it to any of float, int or char pointers. Here we are accessing the de-referenced value (int i=10) but since we are printing %f we get 0.00000.

  8. Ashish Munot
    Ashish Munot :
    7 years ago

    hey how it is possible

  9. Ritanshi Jain
    Ritanshi Jain :
    7 years ago

    Can anyone plzz explain how is this answer correct

  10. Komal Jha
    Komal Jha :
    7 years ago

    How did the answer came 0.000

  11. Akash Algikar
    Akash Algikar :
    8 years ago

    What is the solution anyone??

Related Questions on Pointer