Q. What is the output of the code below considering the size of “short int” is 2, “char” is 1 and “int” is 4 bytes?

Code:
#include <stdio.h>

int main()
{
     short int a = 20;
     char b = 97;
     printf("%d, %d, %d\n", sizeof(a), sizeof(b), sizeof(b + a));
     return 0;
}
  • (A) 2, 1, 1
  • (B) 2, 1, 4
  • (C) 2, 1, 2
  • (D) 2, 2, 8
πŸ’¬ Discuss
βœ… Correct Answer: (B) 2, 1, 4
Explanation: Whenever you have an operator like (+ – * / % << >> & | ^ == != < <= > >=) between two operands of different types, the two types are converted to a common type before the operation is performed.
Explanation by: Admin
Whenever you have an operator like (+ – * / % << >> & | ^ == != < <= > >=) between two operands of different types, the two types are converted to a common type before the operation is performed.

πŸ’¬ Discussion


πŸ“Š Question Analytics

πŸ‘οΈ
251
Total Visits
πŸ“½οΈ
4 y ago
Published
πŸŽ–οΈ
Admin
Publisher
πŸ“ˆ
93%
Success Rate