-8
 #include<stdio.h>
    double i;
    int main()
    {
    (int)(float)(char) i;
    printf("%d",sizeof(i));
    return 0;
    }

Its showing output as 8. Can anyone please explain me why it is showing as 8.? Does the Typecasting have any effect on the Variable i..so that the output can possibly be 4??

1 Answers1

1

(int)(float)(char) i; is not a definition of i. It merely is using the value for nothing.

#include <stdio.h>
double i;
int main(void) {
    i; // use i for nothing
    (int)i; // convert the value of i to integer, than use that value for nothing
    (int)(float)i; // convert to float, then to int, then use for nothing
    (int)(float)(char)i; // convert char, then to float, then to int, then use for nothing
    printf("sizeof i is %d\n", (int)sizeof i);
    char i; // define a new i (and hide the previous one) of type char
    printf("sizeof i is %d\n", (int)sizeof i);
}
pmg
  • 106,608
  • 13
  • 126
  • 198
  • printf("sizeof i is %d\n", (int)sizeof i); Can you explain what does (int)sizeof i does in this statement. It is showing the Output value as 8 And what is the difference between (int)sizeof i and sizeof((int) i) – Kannan Mrithunjai Sep 04 '19 at 15:05
  • `sizeof i` yelds the size of the type of `i`; `(int)sizeof i` converts the size of type of `i` (type `size_t`) to integer so that it can be printed safely with `"%d"` in `printf()`. `sizeof(int)` (or `sizeof((int)i)`) yields the size of int. – pmg Sep 04 '19 at 16:37
  • Got that thanks for your response.. – Kannan Mrithunjai Sep 04 '19 at 17:38