Why Answe is 4 | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Why Answe is 4

#include <stdio.h> int main() { int x; x = sizeof(int); printf("%d",x); return (0); }

26th May 2020, 1:00 PM
Rahul Kumar
Rahul Kumar - avatar
19 Answers
+ 2
It will return the size of int and size of int depend on system
27th May 2020, 4:48 PM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 2
Yes, because size of int differs compiler to compiler. In most of the books and 16 bit systems , the size of int is 2 bytes. And now in modern 32 bit systems , the size of int have become 4 bytes.
28th May 2020, 12:28 PM
Amaan Khan
Amaan Khan - avatar
+ 1
Hi remove those irrelevant links please
26th May 2020, 1:12 PM
Abhay
Abhay - avatar
26th May 2020, 1:16 PM
Rahul Kumar
Rahul Kumar - avatar
+ 1
In 32 bit system int is 4 bytes
27th May 2020, 2:34 PM
Satheesh Kumar
+ 1
Sizeof keyword is present in C to check the datatype storage.It usage in program print the storage in bytes.so here int has storage of 4 bytes
28th May 2020, 10:56 AM
Pallavi Gond
Pallavi Gond - avatar
0
But int datatype is of 2 byte
26th May 2020, 1:04 PM
Rahul Kumar
Rahul Kumar - avatar
0
Tannu Sharma int = 2 bytes, float = 4 bytes , char = 1 byte
26th May 2020, 1:06 PM
Rahul Kumar
Rahul Kumar - avatar
0
Tannu Sharma Means you wants to say int datatype has both 2 bytes and 4 bytes storage
26th May 2020, 1:09 PM
Rahul Kumar
Rahul Kumar - avatar
0
Tannu Sharma Actually it depends on the compiler. Every compiler has it's own rules for such things. Here, the sololearn compiler has size of int data type as 4 bytes.
26th May 2020, 3:59 PM
Jaivrat Das
Jaivrat Das - avatar
0
Range of int data type is 2 or 4 bytes.
26th May 2020, 5:26 PM
Rinki Deopa
0
because the size of an int is 4 bytes , it’s much better if it was written like that Printf("%d bytes ",x);
27th May 2020, 3:47 AM
Soumia
27th May 2020, 4:57 PM
Rahul Kumar
Rahul Kumar - avatar
0
For eg in embedded programming, if you are using 32bit controller then the int is 4bytes or if it is 16bit controller then it is 2bytes.
27th May 2020, 5:02 PM
Satheesh Kumar
0
Okk thanks Satheesh Kumar
28th May 2020, 3:14 AM
Rahul Kumar
Rahul Kumar - avatar
28th May 2020, 3:16 AM
Rahul Kumar
Rahul Kumar - avatar
0
But on top of system as some people are saying, it really depends on the compiler. It's upto a compiler's mechanism that has to take int as 2 or 4 bytes, regardless of the system.
28th May 2020, 3:24 AM
Jaivrat Das
Jaivrat Das - avatar
0
****Look at following Programms you will get better Idea.**** #include<stdio.h> int main() { int a; char ch; float m; double n; long d; short b; printf("\nSize of integer is:%d", sizeof (a)); printf("\nSize of character is:%d", sizeof (ch)); printf("\nSize of float value is:%d", sizeof (m)); printf("\nSize of double value is:%d", sizeof (n)); printf("\nSize of long integer is:%d", sizeof (d)); printf("\nSize of short integer is:%d", sizeof (b)); return 0; } **OUTPUT** Size of integer is:4 Size of character is:1 Size of float value is:4 Size of double value is:8 Size of long integer is:8 Size of short integer is:2
28th May 2020, 9:18 AM
Aniket Gade
Aniket Gade - avatar