0

I am expecting a blank space for the printf("%c",i) while its clearly returning a value after the evaluation of the statement, So I think it should print a blank like or some other value for that matter as it's not null string it's null character.

All i am saying is printf returns some value when the call completes, as it is a function. so when printf("%c",i) is returning some value it should print something.

#include<stdio.h>
int main()
{
    int  i = 0;
    if(printf("%c",i))
        printf("inside if block");
    else
        printf("inside else block");
    return 0;
}
wabavid
  • 11
  • 4
  • 1
    Can you be a little more specific about your problem? What do you want and what is happening? – Prakhar Londhe Feb 19 '20 at 04:48
  • “%c” - that’s how it’s being processed. Now, what’s the result of printf (per the documentation), and how does this not align with expectations presumed by this code/question? – user2864740 Feb 19 '20 at 04:50
  • 1
    ASCII 0 to 31 are known as the "non-printable characters". Why do they have that name, do you think? – Lundin Feb 19 '20 at 09:09

1 Answers1

4

I am expecting a blank space for the printf("%c",i)

printf("%c",0) will print the null character. What is seen on a terminal is implementation dependent. It might be a space, nothing, , , ^@, etc. It has nothing to do with C strings.

i am saying is printf returns some value when the call completes

The return value of printf("%c",i) is "... the number of characters transmitted, or a negative value if an output or encoding error occurred." (C17dr § 7.21.6.3 3). printf("inside if block"); is certainly executed as a 1 is likely returned from (printf("%c",i).

chux - Reinstate Monica
  • 143,097
  • 13
  • 135
  • 256