660 views
0 votes
0 votes
Q)What is the output of the following program segment

#include<stdio.h>

int main()

{

char a = 7 ;

a ^ = 5 ;

printf( "%d", printf( "%d", a + = 3 ) ) ;

return 0;

}

 

A) 5          B) 6                      C) 51                        D) 15

1 Answer

3 votes
3 votes
Option C, 51.

char a = 7 ;

a ^ = 5 ; // a = 7 XOR 5 = 2

printf( "%d", printf( "%d", a + = 3 ) ) ;  /* inner printf prints 5(i.e. a=2+3=5). printf function returns integer, which is the number of characters printed by it. Thus '5' is one character and this, the count 1, is returned to outer printf which prints 1 */

Related questions

0 votes
0 votes
1 answer
3
3 votes
3 votes
5 answers
4
arpit.bagri asked Aug 6, 2023
1,091 views
Why is the output of the below program 36? int main(){ int a = 1; int b = ++a * ++a * ++a; printf("%d", b ); ​​​​ return 0; }