5,558 views

2 Answers

Best answer
2 votes
2 votes

Actually, sizeof operator returns size in bytes and is implementation dependent. Some compilers assign two bytes to int and some four bytes.Characters are internally stored as integers. It seems your integers are stored as 4 bytes.

(i+c) is 4 because 97 is stored as an integer and short is promoted to higher type int berfore addition (97+20) = int so 4 bytes

selected by
0 votes
0 votes

If you want that your size of data type remain same in every compiler u can use int8_t (which will allocate 8 bit) and int16_t will allocate 16 bit (2 byte), int32_t will allocate 4 byte (32 bit) .

Related questions

0 votes
0 votes
1 answer
2
2 votes
2 votes
2 answers
3
atulcse asked Jan 15, 2022
693 views
Consider the following programint find (int n) { int a = 1; for (i = 1; i < = n; i ++) for (j = 1; j < = i; j++) for (k = 1; k <= j, k++) a = a + 1; ...
0 votes
0 votes
3 answers
4
ramakrushna asked Dec 23, 2021
742 views
What should be the ans. Isn’t the Function initialization should be outside main function? They are given inside main. If declaration would be outside main then ans sho...