• retagged by
1,392 views
1 1 vote
What is the output of following program

#include<stdio.h>

int main()
{
    short int i=20;
    char c=97;
    printf("%d,%d,%d\n",sizeof(i),sizeof(c),sizeof(c+i));
    return 0;
}

(A)2,1,2

(B)2,1,1

(C)2,1,4

(D)2,2,8

2 Answers

0 0 votes

On most systems: sizeof(short int) = 2  So first output = 2

sizeof(c) c is a char.sizeof(char) = 1

In an arithmetic expression, C applies integer promotion rules:

  • char and short are promoted to int before the operation.

Position:
Show:

Related questions

0 0 votes
1 answers 1 answer
790
790 views
Souvik33 asked Jan 29, 2023
790 views
Consider the following C code snippets, labeled as P1, P2 and P3, the output of P1 is “X”, of P2 is “Y” and of P3 as “Z”. What is the value of “X+Y+Z”P1#include <stdio.h ...
0 0 votes
0 0 answers
1.1k
1.1k views
air1ankit asked Jul 12, 2018
1,119 views
que Study the following program written in a block structured language.var p, q : integer;begin p:= p+q; q:= p−q; p:= p−q;end;(a) exchang...
0 0 votes
1 1 answer
7.6k
7.6k views
Harikesh Kumar asked Jun 3, 2017
7,645 views
If the address of A and A are 1000 and 1010 respectively and each element occupies 2 byte then the array has been stored in which order ?1.row major 2.column major 3....
4 4 votes
1 1 answer
1.6k
1.6k views
Ravi prakash pandey asked Nov 12, 2017
1,600 views
what wil be sizeof(void)and sizeof(void *)