393 views
0 votes
0 votes

when i printing x it is giving 0 but when comparing x with 5 ,it executing else part ,means condition fail ,why ??

#include <stdio.h>

int main(void) {
int x;
     if(x=(printf("Hello")) != 5)
      printf("Hello");
   else
      printf("World \n");
     printf("%d  \n",x);
    return 0;
}

https://ideone.com/NJSj2i

1 Answer

0 votes
0 votes
yes as printf returns number of characters it print so here printf("Hello") will return 5 and the condition 5!=5 become false due to which x will get 0.Change "HELLO" with "HY" 2!=5 true hence x=1

Related questions

2 votes
2 votes
3 answers
1
Gurdeep Saini asked Jan 14, 2019
1,695 views
#include <stdio.h>int arr[] = { 10, 20, 30, 40, 50 };static int count ;inc() {return ++count;}int main(){arr[count++]=inc();printf("%d ", arr[count]);printf("%d ", arr[0]...
0 votes
0 votes
0 answers
2
utkarshkosta asked Dec 22, 2018
364 views
#include<stdio.h int main() { char A[5][7][6]; char *p[5][7][6]; printf(“%d\t”,(unsigned)(A+1)-(unsigned)A); printf(“%d”,(unsigned)(p+1)-(unsigned)p); } OPTIONS:4...
1 votes
1 votes
2 answers
3
rahul sharma 5 asked Dec 14, 2016
447 views
For n=2 the P is coming as 3,but none of the option is satisfying?